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.
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.
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.
Related concepts
- Mapused by · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- unhashablecontrasts with · 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.
- statecontrasts with · State is information or a configuration describing the condition of a system, entity, or computation at a particular time and potentially influencing subsequent behavior or decisions.
- immutable collectionequivalent to · An immutable collection is a collection whose membership and contents cannot be changed after creation.
- similarity searchproduces · Similarity search is a retrieval technique that finds or ranks items by comparing their representations with a query according to a similarity or distance measure.
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.


