Python Function Reference

frozenset

Create an immutable set from the items of an iterable.

Python 3.13
frozenset([iterable])

Parameters

iterableIterableoptional
The items of the new set; without it, an empty set is created.

Return value

A new immutable set without duplicates.

Examples

Immutable set without duplicates

Python 3.13
print(frozenset([1, 2, 2, 3]))
frozenset({1, 2, 3})

Set as a dictionary key

Python 3.13
routes = {frozenset({'A', 'B'}): 120}
print(routes[frozenset({'B', 'A'})])
120

Details

A frozenset cannot be changed after creation, but it can be a dictionary key or an item of another set.

See also

Where to learn