A thing in python that really freaks me out is this error: TypeError: unhashable type
.
Ideally i would like to have a data structure where i just use sets instead of lists so i can use the set operators like this:
a = {({1,2}, 'alpha'), ({2,3}, 'beta')}
b = {({1,2}, 'alpha')}
c = a - b # c = {({2,3}, 'beta')}
I can not even create a set that contains sets because i get the TypeError: unhashable type: set
So i try to use a list instead of a set. this way i can at least assign the values for a and b. but using the set method again to substract one set from another leads to the same error:
a = [({1,2}, 'alpha'), ({2,3}, 'beta')]
b = [({1,2}, 'alpha')]
c = list(set(a) - set(b)) # c = [({2,3}, 'beta')]
I tried it with a dictionary instead of a list, same error.
Question: How can i compare two bunches containing elements that somewhere contain sets?
Or am i thinking fundamentally wrong/ "not pythonic" and the error is rooted in the data structure itself?
Thanks for your help!
Muff