It is implemented, but you need to use a hashable type instead. frozenset()
is that type. The documentation even tells you so:
To represent sets of sets, the inner sets must be
frozenset
objects.
Demo:
>>> {2, frozenset([3, 4])}
set([frozenset([3, 4]), 2])
This is because a regular set()
is mutable, which is incompatible with the requirements of the datastructure used for sets (and dictionaries); these require stable objects that can be re-located when used as a key in a table based on their hash.
The documentation again:
The
set
type is mutable — the contents can be changed using methods likeadd()
andremove()
. 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. Thefrozenset
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.