Dictionary
PronunciationDIK-shuh-ner-ee
Definition
A dictionary stores data as key-value pairs, so you can find a value quickly by its key instead of its position.
Where you hear it
In Python code, JSON handling, and discussions of fast lookups, also called hash maps or objects in other languages.
Examples
We keep the user's settings in a dictionary keyed by name.
Looking up a key in a dictionary is much faster than searching a list.
Store the color codes in a dictionary keyed by the color name.
Common mistake
Reading a missing key directly raises an error. Use get() with a default when the key may not exist.
Don't confuse with
A list, which is found by position. A dictionary is found by key, and its keys must be unique.
Say it at work
- In a meeting or chat
Let's use a dictionary here instead of scanning the whole list.
- In an email or ticket
Key the dictionary by id so we can look each item up instantly.
Keep exploring
More in Programming Fundamentals