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 →

What to know first

Related concepts

Questions about unhashable

What is 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.

Which Manning books explain unhashable?

Python How-To and Python Workout: 50 ten-minute exercises.

What should I know before learning unhashable?

Manning books that teach unhashable usually introduce Map first.

What is the difference between unhashable and Map?

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. A map is an associative data structure that stores key-value associations and supports retrieving values by key.

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.