TypeError: unhashable type: 'list'
Python · updated 2026-11-04
Raised when Python needs a hash of a value: using it as a dict key, adding it to a set, set(), dict.fromkeys(), a group-by key, or functools.lru_cache on a function called with a list. Lists, dicts and sets can change, so they can't be hashed.
Traceback (most recent call last):
File "/app/reports/group.py", line 19, in group_by_tags
buckets[row["tags"]].append(row)
TypeError: unhashable type: 'list'Quick fix
Look at what is used as the key in the failing line. If the list's contents identify the item, convert it: tuple(tags) (or tuple(sorted(tags)) when order doesn't matter) or frozenset(tags). If you meant to check membership of each item, loop over the list instead. For lru_cache, pass tuples instead of lists.
- Find the key or set member in the failing line and print its type.
- Convert a list to tuple(...) or frozenset(...) when it is used as a key.
- Use tuple(sorted(...)) when ['a', 'b'] and ['b', 'a'] should be the same key.
- Dicts as keys: use a stable ID field, or tuple(sorted(d.items())) if the values are hashable.
- lru_cache / cache: change the arguments to tuples, or cache by an ID.
from collections import defaultdict
buckets = defaultdict(list)
for row in rows:
# Before: buckets[row["tags"]] -> TypeError: unhashable type: 'list'
key = tuple(sorted(row["tags"]))
buckets[key].append(row)
seen = set()
for item in items:
seen.add(frozenset(item["permissions"])) # sets of sets need frozensetWhy it happens
A list used as a dict key
Grouping or counting by a field that is a list (tags, coordinates, a composite key built with [] instead of ()).
Adding lists or dicts to a set
Deduplicating rows with set(rows) when each row is a list or dict.
Caching with list arguments
functools.lru_cache and cache hash their arguments, so a cached function called with a list fails the first time.
pandas group keys and index values
A column holding lists used in groupby or as an index raises the same error from inside pandas.
Other fixes
- To deduplicate dicts by content, use json.dumps(d, sort_keys=True) as the key, or a dict keyed by the record ID.
- A dataclass with frozen=True is hashable and makes a clear composite key.
Same error, other wording
- TypeError: unhashable type: 'dict'
- TypeError: unhashable type: 'set'
- TypeError: unhashable type: 'numpy.ndarray'
Let your coding agent catch the next one
Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:
> Find the "unhashable type: 'list'" errors in production, show me which value was used as a key or set member, and convert it to a hashable form (tuple, frozenset or an ID) that keeps the intended meaning.
Related errors
- KeyError: 'email'
- AttributeError: 'dict' object has no attribute 'name'
- TypeError: 'NoneType' object is not iterable
More in Undefined, None and type errors
- TypeError: Cannot read properties of undefined (reading 'x')Node.js
- TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined.Node.js
- TypeError: Cannot convert undefined or null to objectNode.js
- TypeError: items is not iterableNode.js
- TypeError: x is not a functionNode.js
- TypeError: Client is not a constructorNode.js
- ReferenceError: x is not definedNode.js
- ERR_INVALID_ARG_TYPE: The "path" argument must be of type string. Received undefinedNode.js
- TypeError: 'NoneType' object is not subscriptablePython
- AttributeError: 'NoneType' object has no attribute 'x'Python
- IndexError: list index out of rangePython
- TypeError: unsupported operand type(s) for +: 'int' and 'str'Python
- ValueError: invalid literal for int() with base 10: ''Python
- TypeError: __init__() got an unexpected keyword argument 'proxies'Python
- UnboundLocalError: cannot access local variable 'total' where it is not associated with a...Python
- RuntimeError: dictionary changed size during iterationPython
- ValueError: too many values to unpack (expected 2)Python
- TypeError: 'str' object is not callablePython
References: Python glossary: hashable, Python docs: built-in types (tuple, frozenset, dict)