'Why can't I put this tuple ([0, 2], [3, 4]) into a set in Python?
Why can't I put this tuple ([0, 2], [3, 4]) into a set in Python?
I got the following error when I tried:
TypeError: unhashable type: 'list'
Solution 1:[1]
Attempting to put a tuple inside a set or a dict's keys requires all of the tuple's values to be hashable (for internal comparison).
Since lists are mutable, and the same object can change, it's impossible to hash and later compare, and therefore hashing is completely blocked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bharel |
