python
typing
ai_generated
true
TypeError: unhashable type: 'list'
ID: python/typeerror-unhashable-list
97%Fix Rate
98%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 310 | active | — | — | — |
| 311 | active | — | — | — |
Root Cause
Attempting to use a list as a dict key or set element.
genericWorkarounds
-
97% success Convert list to tuple before using as dict key or set element
Use tuple(my_list) as the key instead
Sources: https://docs.python.org/3/glossary.html#term-hashable
-
90% success Use frozenset() if order doesn't matter
frozenset(my_list) is hashable and order-independent
Dead Ends
Common approaches that don't work:
-
Wrapping the list in str() to make it hashable
70% fail
Loses structure; str representation can collide for different lists
-
Using json.dumps() as hash key
55% fail
Fragile — key ordering matters, wastes memory
Error Chain
Frequently confused with: