We know that in Python a set can be defined by writing out all its elements as follows:
a_set={1,"xyz"}
And Python books all say that collection elements can be any data types. Therefore, we should be able to record a set containing a set. I tried to write it as:
a_set={1,{"xyz"}}
But IDLE reported an error:
Traceback (most recent call last): File "<pyshell#58>", line 1, in <module> a_set={1,{"xyz"}} TypeError: unhashable type: 'set'
I think this may be because Python is trying to understand this as a dictionary. Then, how to write a collection containing a collection in Python?
user2384994
source share