Caffeinated Coder
Book an appointment
Lesson 08 · Collections and functions

Dictionaries and sets

A list finds things by position. A dictionary finds them by name: it stores key: value pairs, so ages["Ana"] gives Ana's age straight away. Step through a seven-line program, ages.py, that builds a dict, adds a pair, changes a value, looks keys up (safely, with get()), then builds a set and watches it drop a duplicate. Along the way, see the trick that makes both fast: Python hashes each key to work out where it belongs.

12 min9 steps5 questionsBeginner
Fig 8 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.