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.

  1. Find the key or set member in the failing line and print its type.
  2. Convert a list to tuple(...) or frozenset(...) when it is used as a key.
  3. Use tuple(sorted(...)) when ['a', 'b'] and ['b', 'a'] should be the same key.
  4. Dicts as keys: use a stable ID field, or tuple(sorted(d.items())) if the values are hashable.
  5. lru_cache / cache: change the arguments to tuples, or cache by an ID.
python
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 frozenset

Why 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.

Plans from $29/moSee what your agent readsSee the setupCancel any time from the billing portal

Related errors

More in Undefined, None and type errors

References: Python glossary: hashable, Python docs: built-in types (tuple, frozenset, dict)