Comprehensions
A comprehension builds a new collection from an old one in one expression: [n * 2 for n in numbers if n > 0]. Read it as “for each, if, do this”.
Five lines of loop, or one line that says exactly the same thing.
Comprehensions let students express filtering and transforming as a single readable expression. Combined with confident handling of nested data, this is the toolkit for reshaping real-world information.
Data arrives in the wrong shape almost always. Reshaping it quickly and correctly is the everyday work of anyone who codes with data.
Three core ideas, each taught with worked examples and then practised until it feels obvious.
A comprehension builds a new collection from an old one in one expression: [n * 2 for n in numbers if n > 0]. Read it as “for each, if, do this”.
Nested data needs careful traversal — a list of dictionaries each containing a list. Naming loop variables honestly prevents most confusion.
Transformations convert between shapes: list to dictionary, grouped by category, filtered and sorted. This is the core of data preparation.
Comprehension syntax comes from set-builder notation in mathematics: {x² | x ∈ N, x < 10} translates almost directly into Python.
“Shorter is always better.” A comprehension four levels deep is worse than a plain loop. Clarity wins over compression.
Sessions 9–16 of the 72-session year, at two one-hour sessions per week.
Where this module fits, what you will build, and a hands-on starter that gets everyone curious about comprehensions.
Guided teaching on comprehensions, worked through together with the teacher.
Independent practice, small challenges and one deliberate mistake to diagnose.
Guided teaching on nested data, building directly on the previous two sessions.
Applied tasks that combine comprehensions and nested data in one piece of work.
Transformations introduced and practised, completing the toolkit needed for the project.
Guided build session for the module project: Data-cleaning challenge.
Finish, test against the checklist, present the work and explain the decisions behind it.
Every module ends with something the student built themselves and can demonstrate. This is the piece that goes into their portfolio and gets explained out loud at the end of session 16.
Take a messy dataset and clean it using only comprehensions, then rewrite the same work as loops and decide honestly which reads better.
Students finishing Module 2 can:
The vocabulary introduced here, in plain language:
6 quick questions drawn from this module — vocabulary, the project you build, and a myth-or-fact round. Every wrong answer explains itself, so a mistake still teaches you something.
Tell us your child’s class and what they enjoy. We will suggest the closest program fit—no pressure and no upfront payment.