Dictionaries – Iteration
Iterating a dictionary with a for loop visits each key in turn
Understanding Dictionaries – Iteration in Python
What it does: .items() provides (key, value) tuples. k, v unpacks each pair. 'in' checks if a key exists in the dict — prevents KeyError. Iterating a dict directly gives you the keys — same as for key in d.keys():. You must call .values() explicitly — for v in d: gives keys, not values. .items() returns (key, value) pairs — then unpack them into k and v. Looping over d directly yields the keys — 'a' and 'b', not the values. Python uses the in operator — dicts don't have a .has() method. Changing a dict's size mid-loop raises RuntimeError — loop a copy instead.
Common mistakes: Looping over d directly gives only keys. Use .items() for key-value pairs. for val in d: gives KEYS, not values. Use .values() for values.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 31–40) and word search (Modules 21–40).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
for key in d:Fill in the Blanks
Spot the Error
Student with a class code? Join your class →