Codele / Programming basics
Dictionaries: look things up by name
A list finds things by position. A dictionary finds them by name, like a price list or a phone book. Pick an item and watch the lookup.
- A dictionary stores pairs: a key (the name) and a value (what it points to).
- You look things up by key, not by position. The order does not matter.
- Setting a key that is new adds a pair. Setting a key that exists replaces its value.
- Check that a key is there before you look it up. A missing key can cause an error or a wrong answer.
- Use a list when order matters. Use a dictionary when names matter.
Loading the playable lesson…