Immutable membership collections
Representing a fixed, unordered collection of values
Python · Class
frozenset creates an immutable, hashable set of unique elements. It is useful as a dictionary key or as an element of another set when the collection itself must remain fixed.
Call frozenset with an iterable to create an immutable set of its elements. Because the contents cannot change, a frozenset is hashable and can serve as a dictionary key or as an element inside another set; it supports set operations but not mutating operations.
class frozenset(iterable=(), /)| Name | Type | Description |
|---|---|---|
iterable | iterable | An optional iterable whose elements are used to create the new frozenset; it defaults to an empty iterable. |
A new frozenset object containing the elements taken from iterable.
allowed = frozenset({"read", "write"})
permissions = {allowed: "editor"}
print("write" in allowed)
print(permissions[allowed])Creates an immutable set of permissions and uses it as a dictionary key.
Representing a fixed, unordered collection of values
Using a collection of values as a dictionary key
Nesting one set-like collection inside another
setfrozenset.unionfrozenset.intersectionfrozenset.differencefrozenset.symmetric_difference