I have a list of lists, and I want to turn it into a set of lists, in order to compare it with other sets.
For example, I want to do:
mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
myset = set(mylist)
myset
And get:
{[1, 2, 3], [4, 5, 6], [7, 8, 9]}
But this error pops up:
Traceback (most recent call last):
File "A:/Users/.../Testfile.py", line 2, in <module>
myset = set(mylist)
TypeError: unhashable type: 'list'
I also tried this, a solution posted at https://stackoverflow.com/questions/30773911/:
myset = set(x for lst in mylist for x in lst)
print(myset)
But this merges all of the internal lists.
{1, 2, 3, 4, 5, 6, 7, 8, 9}
Is there a way to convert mylist
into a set of lists?