s = ["this", "that", "this"]
Why does set(s)
work but {s}
fails with
TypeError: unhashable type: 'list'
s = ["this", "that", "this"]
Why does set(s)
work but {s}
fails with
TypeError: unhashable type: 'list'
It's because they mean different things. set(s)
iterates s
to create a set, whereas the literal syntax {s}
just attempts to create a set containing the single element s
.
>>> set("abc")
{'a', 'b', 'c'}
>>> {"abc"}
{'abc'}
Try {*s}
instead for the equivalent of set(s)
.