TypeError: Unhashable Type 'dict'

TypeError: unhashable type: 'dict'

Quick Answer

You are trying to use a dictionary as a set element or dictionary key. Dicts are mutable and cannot be hashed. Convert to a frozenset of items or use a hashable representation.

Why This Happens

Like lists, dictionaries are mutable and therefore unhashable. They cannot be used as dictionary keys or set elements. If you need to use dict-like data as a key, convert it to a tuple of sorted items or a frozenset.

The Problem

seen = set()
record = {'name': 'Alice', 'age': 30}
seen.add(record)

The Fix

seen = set()
record = {'name': 'Alice', 'age': 30}
seen.add(frozenset(record.items()))

Step-by-Step Fix

  1. 1

    Convert to hashable type

    Use frozenset(dict.items()) or tuple(sorted(dict.items())).

  2. 2

    Use a different key

    If the dict has a unique identifier field, use that as the key instead.

  3. 3

    Consider named tuples

    Use collections.namedtuple or dataclasses with frozen=True for hashable record types.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free