Dictionaries – Iteration
Iterating a dictionary with a for loop visits each key in turn
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 journey and assign it to your class.
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
Create a free class, add this module to a journey, and track who's stuck.
Create a free teacher account →No credit card. No setup fee. Make a class and invite students in under three minutes.
Practice this topic interactively, track progress, and unlock badges.
Start Learning Free →