WeCodeAcademy

List Comprehensions

A list comprehension builds a list in one line: [expression for item in items if condition].

Examplepython
Open in editor »
Quick check

What does `[n * 2 for n in [1, 2, 3]]` produce?

Your turn: write the code

Use a list comprehension to build the squares of 1 to 5 and print the list.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.