liveBook · Manning

Hashable

A hashable object has a stable hash value and compatible equality behavior, allowing it to be used as a dictionary key or set element.

How 3 Manning books explain it

Python How-To

A hashable object is a Python object with a stable hash value and equality behavior that allow it to serve as a dictionary key or set element.

How it is used
Guides the choice of objects used as dictionary keys and set elements.
How deep it goes
Explains hash consistency, collisions, mutability, common types, and runtime checks, but does not detail hash-table implementation protocols.
Examples
Uses failed dictionary and set constructions, hash calls, and a Hashable-based type-checking script.
What you can do after
Diagnose TypeError failures and select suitable dictionary keys or set elements using Hashable checks.

Read how Python How-To explains hashable →

Python Workout: 50 ten-minute exercises

A hashable type has values with stable hash values and can therefore be used for dictionary keys or set elements.

How it is used
Explains why dictionary keys must be hashable and how that requirement supports unique, efficient lookup.
How deep it goes
Defines hashability through hash(), contrasts O(n) sequence search with O(1) dictionary lookup, and only raises collision handling.
Examples
Uses an office-directory analogy and contrasts strings, lists, and tuples with dictionary lookup.
What you can do after
Understand which values can serve as dictionary keys and why hashing makes lookup efficient.

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

Python Workout, Second Edition

A hashable object is a Python object with a stable hash value that can be used as a dictionary key.

How it is used
Uses hashability to determine which Python objects can act as dictionary keys and support efficient lookup.
How deep it goes
Explains hash functions through lookup behavior and complexity, but stops short of implementation details.
Examples
Uses numbers and strings as keys and contrasts unrestricted dictionary values with unique keys.
What you can do after
Apply it by selecting hashable objects for dictionary keys while storing arbitrary values.

Read how Python Workout, Second Edition explains hashable →

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.