Dictionaries – Advanced (comprehensions, merging)
A dict comprehension builds a dictionary in one expression; the | operator merges two dicts
Understanding Dictionaries – Advanced (comprehensions, merging) in Python
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 class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 51–63) and word search (Modules 41–63).
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
Student with a class code? Join your class →