i can't add set to python
you can add tuple to python set
a={1,2,3,4,5}
a.add((10,11,12))
when i try same with set
a={1,2,3,4,5}
a.add({10,11,12})
TypeError: unhashable type: 'set'
You can add frozenset
s to a set
, since they are hashable (because they are immutable).
a = {1,2,3,4,5}
a.add(frozenset([10,11,12]))
I'd assume you are trying to get:
{1, 2, 3, 4, 5, 10, 11, 12}
You are appending a set which is unhashable. And when you add the tuple you will get:
{1, 2, 3, 4, 5, (10, 11, 12)}
You are trying you get the union:
a.union({10,11,12})
Or:
a | {10,11,12}
{1, 2, 3, 4, 5, 10, 11, 12}
, or{1, 2, 3, 4, 5, {10, 11, 12}}
? The latter is what this code tries to do.