python - Unique items in list of sets -


if have list of sets:

>>> lst = [{1, 2}, {0, 1}, {1, 2}] 

how return unique items?

trying known set() not work:

>>> set(lst) typeerror: unhashable type: 'set' 

if "unique items" mean unique sets, use frozenset, hashable immutable version of set. either build sets frozenset objects initially, or if need mutate them, like:

uniques = set(frozenset(s) s in lst) 

then:

>>> uniques set([frozenset([1, 2]), frozenset([0, 1])]) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -