🧩Dictionary
Also known as Map, Hash Map, Associative Array, dict
A collection of key and value pairs. You look a value up by its key.
Think of it like
Think of it like a coat check. You hand over a ticket, and you get back your own coat.
Example
A class app keeps ages as {"Emma": 36, "Jack": 12}. Asking for "Jack" gives back 12 at once.
Why it matters
Settings, user records and counts are all looked up by name. A dictionary finds them without searching the whole list.
Definition
Example code
python
>>> ages = {"Emma": 36, "Jack": 12}
>>> ages["Jack"]
12
>>> ages["Bo"]
KeyError: 'Bo'Common mistake
Key takeaways
- 1Key and value. Every entry is a pair.
- 2Keys are unique. Each key can appear only once.
- 3Fast lookup. Find by name, not by position.