+ 6

What is a frozen set in Python?

15th Feb 2020, 6:33 AM
SHADOW 🌀
SHADOW 🌀 - avatar
4 Respostas
+ 11
"There are currently two built-in set types, set and frozenset. The set type is mutable — the contents can be changed using methods like add() and remove(). Since it is mutable, it has no hash value and cannot be used as either a dictionary key or as an element of another set. The frozenset type is immutable and hashable — its contents cannot be altered after it is created; it can therefore be used as a dictionary key or as an element of another set."
15th Feb 2020, 6:49 AM
Aman[A.I]
Aman[A.I] - avatar
+ 8
frozenset is an immutable set similar to: tuple is an immutable list The frozenset cannot be changed after its creation, but acts like a set, you can do intersect, set difference etc. operations on it, but can't slice it like a list or tuple. You can use frozenset as dictionary key, because it is hashable (unlike a set). https://stackoverflow.com/questions/14422409/difference-between-tuples-and-frozensets-in-JUMP_LINK__&&__python__&&__JUMP_LINK
15th Feb 2020, 7:56 AM
Tibor Santa
Tibor Santa - avatar
15th Feb 2020, 6:54 AM
Ipang
17th Feb 2020, 3:20 AM
VAMSI
VAMSI - avatar