TypeError: unhashable type: 'list'
Updated
The Python error "unhashable type: 'list'" means a list was used as a dict key or set member. Python 3.14 words it as "cannot use 'list' as a dict key". The fix.
What you see
visits = {}
name = ["Ada", "Lovelace"]
visits[name] = 1Traceback (most recent call last):
File "/home/me/project/main.py", line 3, in <module>
visits[name] = 1
~~~~~~^^^^^^
TypeError: cannot use 'list' as a dict key (unhashable type: 'list')What it means
A dict finds keys, and a set finds members, by their hash: a number computed from the value. That number must never change while the item is stored. A list can change, so it has no hash, and Python refuses to use it as a key.
Python 3.14 rewrote the message to say what you were doing, "cannot use 'list' as a dict key", with the old wording kept in brackets.
Why it happens
- A list as a dict key, as in the example.
- Adding a list to a set, or
set(rows)where each row is a list. - A dict inside a set or as a key, which gives "unhashable type: 'dict'".
- A tuple that contains a list. Tuples are hashable only when everything in them is; Python 3.14 reports this as "cannot use 'tuple' as a dict key (unhashable type: 'list')".
How to fix it
Use a tuple, which cannot change and so can be hashed:
visits[tuple(name)] = 1 # key is ("Ada", "Lovelace")
unique_rows = {tuple(row) for row in rows}
For a set of sets, use frozenset. For a dict as a key, turn it into something fixed, such as tuple(sorted(d.items())).
Example: a list in a set
seen = set()
seen.add([1, 2])Traceback (most recent call last):
File "/home/me/project/main.py", line 2, in <module>
seen.add([1, 2])
~~~~~~~~^^^^^^^^
TypeError: cannot use 'list' as a set element (unhashable type: 'list')| Python | Prints |
|---|---|
| 3.9–3.13 | TypeError: unhashable type: 'list' |
| 3.14–3.15 | TypeError: cannot use 'list' as a set element (unhashable type: 'list') |
Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.
How each Python version words it
| Python | Prints |
|---|---|
| 3.9–3.13 | TypeError: unhashable type: 'list' |
| 3.14–3.15 | TypeError: cannot use 'list' as a dict key (unhashable type: 'list') |
Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.
Up to 3.13 both examples print "unhashable type: 'list'". 3.14 and later name the container: "cannot use 'list' as a dict key" or "as a set element", followed by the old text in brackets.
Questions
Why can strings and tuples be keys?
They are immutable: a string or tuple never changes after it is made, so its hash stays valid.
Can I make my own class hashable?
Instances of your classes are hashable by default, by identity. If you define __eq__, define __hash__ as well, or Python sets it to None and the instances become unhashable.
Sources
- Glossary: hashable, Python documentation
- Data model:
__hash__, Python language reference - What's New in Python 3.14: improved error messages, Python documentation
Read on October 25, 2026.