Frozenset¶

Frozenset is also a set, but immutable and hashable. Reminds you of the difference between a list and a tuple, doesn't it? Frozenset has no advantages over set in terms of memory usage or performance speed; its hashability (and consequently, the ability to be used as a dictionary key) is the only advantage of frozenset.

In [4]:
a = set({'New-York', 'Los Angeles', 'Ottawa'})
b = frozenset({'New-York', 'Los Angeles', 'Ottawa'})

print(f'Set: {a.__sizeof__()} bytes')
print(f'Frozenset: {b.__sizeof__()} bytes')
Set: 200 bytes
Frozenset: 200 bytes