Step: List comprehension: transform

List comprehension: transform

A list comprehension [expr for item in iterable] builds a new list by applying expr to every item — a compact alternative to a for loop with .append().

Why it matters: comprehensions are the idiomatic, most-read Python way to transform a list.

Example: [n + 1 for n in [1, 2, 3]] is [2, 3, 4].

Your turn: square every number in numbers with [n * n for n in numbers].

Pitfall: comprehensions build the whole list in memory at once — for huge sequences a generator (later in this tutorial) is more memory-friendly.

Setup:
numbers = [1, 2, 3, 4, 5]
Your code:
Expected output:
[1, 4, 9, 16, 25]
Step 5 of 18