Dictionaries – Advanced (comprehensions, merging)
A dict comprehension builds a dictionary in one expression; the | operator merges two dicts
What it does: .items() yields (key, value) pairs for each entry in the dict. The pipe | merges dicts - if both have the same key, the right side value wins. zip pairs the two lists, dict() converts those pairs into a dictionary. Add 'if condition' before the closing brace to filter - only pairs where condition is True get included. Unpacking k, v then using v: k reverses which side is the key and which is the value. The right dict overwrites matching keys - think of it as d1 updated with d2. zip(['a','b'], [1,2]) gives ('a',1) then ('b',2) - like a zipper joining two lists.
Common mistakes: Dict comprehensions use curly braces {}, not square brackets []. Dicts don't support +. Use | or {**d1, **d2} to merge.
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
Dict comprehensionFill 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 →