Why This Happens
Python requires dictionary keys and set elements to be hashable. Since lists can be modified after creation, their hash could change, so Python forbids their use as keys. Tuples, being immutable, are hashable.
The Problem
coords = {[0, 0]: 'origin', [1, 1]: 'point'}The Fix
coords = {(0, 0): 'origin', (1, 1): 'point'}Step-by-Step Fix
- 1
Find the unhashable object
Look at the line where you create a dict or set and find where a list is used as a key or element.
- 2
Convert to tuple
Replace the list with tuple(your_list) or use parentheses instead of brackets.
- 3
Use frozenset for set-of-sets
If you need a set containing sets, use frozenset() instead of set().
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