Skip to content

Archive

Collections

1 articles
Python 03 Sep 2026 11 min read

Design Hashable Python Objects Correctly

Python dictionaries and sets make lookups feel simple: give them a key or value, and they can usually find it quickly. That convenience depends on a contract that becomes important as soon as you create your own value-like classes. A dictionary key is not located by equality alone. Python first uses the object’s hash value to narrow the search, then uses equality to distinguish candidates that land in the same area of the hash table.