computer-science/hash-tables-how-python-finds-a-key-without-searching-for-it.md

Hash tables: how Python finds a key without searching for it

Computer science · 4 min read ·

You type `ages["cat"]` and Python answers instantly, even with a million entries. It does not search. It calculates where "cat" must be stored.

A hash table turns each key into a number, squeezes that number into one of a few buckets, and opens that bucket directly. Play with a tiny 8-bucket table, watch two keys collide, and see why `dict` and `set` stay fast as they grow.