Skip to content

Lists · warm-up

Squares of the evens

Write even_squares(nums) returning a new list of the squares of the even numbers, in order. [1, 2, 3, 4] gives [4, 16].

Try it as a list comprehension: [expression for x in nums if condition].

Run adds print(even_squares([1, 2, 3, 4])) after your code, to try it.

Stuck on the idea rather than the code? The Comprehensions and slices lesson walks through it.