List comprehensions
A list comprehension builds a new list from a loop in one expression. Add 'if condition' to filter items, or change x (e.g. x * 2) to transform each item.
Understanding List comprehensions in VCE Software Development U4O1
What it does: This is the basic form [x for x in items]: loop over items and collect each x into a new list. The expression at the start (n.upper()) changes each item before it is added to the new list. A filter condition goes at the END of the comprehension, after the loop part: [m for m in marks if m >= 50]. A comprehension creates a new list. The original is only changed if you assign the result back to the same variable name. The 'if x > 10' part filters items. Only items that pass the condition are included in the new list.
Common mistakes: The keyword 'in' is missing. A list comprehension needs 'for x in xs' to loop over the list, so the line should be hi = [x for x in xs if x > 5]. Round brackets create a generator, not a list. A list comprehension uses square brackets: dbl = [p * 2 for p in prices].
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 82–114) and word search (Modules 3–114).
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
[x for x in items]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →