Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

frozenset()

Creates an immutable set of distinct hashable elements.

Version: Python 3.14; repository image, production runtime not attested

Syntax

frozenset([iterable], /)

Creates an immutable set of distinct hashable elements.

A frozen set can itself serve as a dictionary key. Duplicated input members represent the same key.

The result is a hashable immutable set of hashable elements. Membership determines equality, so duplicate a and reversed input order do not change the key. Looking up the second frozenset finds the stored value 7. A nested mutable list cannot be a member and raises TypeError.

a = frozenset(["a", "b"])
b = frozenset(["b", "a", "a"])
assert a == b and hash(a) == hash(b) and {a: 7}[b] == 7

Examples

labels = {frozenset(["a", "b"]): 7}
print(labels[frozenset(["b", "a", "a"])])

Result

7

The result is a hashable immutable set of hashable elements. Membership determines equality, so duplicate a and reversed input order do not change the key. Looking up the second frozenset finds the stored value 7. A nested mutable list cannot be a member and raises TypeError.

Sources