Why must dictionary keys be hashable, and what does that imply for lists?
PICTURE THIS: PYTHON TYPES
Simple meaning
Dicts locate entries by hash then equality, so a key must implement a stable __hash__ and __eq__.
WHY — Data Types instead of guessing?
Why interviewers care about Data Types:
on Data Types.
the situation, the default choice, and one exception - that reads as experience.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1Dicts locate entries by
hash then equality, so a key must implement a stable __hash__ and __eq__.
- 2Lists are mutable, so
their contents could change after insertion and break the hash table
- 3How it works
they are unhashable.
- 4Tuples of hashables work
as keys
- 5tuples that contain a
list do not.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
Dicts locate entries by hash then equality, so a key must implement a stable __hash__ and __eq__. Lists are mutable, so their contents could change after insertion and break the hash table