liveBook · Manning

Unhashable

In Python, unhashable describes an object that cannot be used as a dictionary key or set element because it lacks a suitable stable hash value.

How 2 Manning books explain it

Python How-To

An unhashable object is a Python object that cannot serve as a dictionary key or set element because it lacks the required stable hashability.

How it is used
Explains why dictionaries and sets reject mutable objects and how to choose containers for retrieval or membership operations.
How deep it goes
Explains TypeError, stable hash values, mutability conflicts, common types, and runtime checking without descending into hashing algorithms.
Examples
Uses failed dictionary and set constructions, hash calls, a hashability-checking loop, and comparisons of mutable and immutable types.
What you can do after
Diagnose TypeError from invalid dictionary keys or set elements and check candidate values with collections.abc.Hashable.

Read how Python How-To explains unhashable →

Python Workout: 50 ten-minute exercises

Unhashable describes a Python object whose value cannot be used as a dictionary key or set element because it lacks a suitable stable hash value.

How it is used
Explains why dictionaries and sets require objects whose hash remains stable.
How deep it goes
Explains mutation, changing hashes, and unreachable key-value pairs while deferring finer distinctions between hashability and immutability.
Examples
Uses mutable lists as dictionary keys to demonstrate why changing a key could make its stored value unfindable.
What you can do after
Diagnose why a mutable object cannot be used as a dictionary key or set element.

Read how Python Workout: 50 ten-minute exercises explains unhashable →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.