Squares of the Even Numbers

Easy ⏱ 8 min 82% acceptance ★★★★☆ 4.4
Write even_squares(nums) that returns a list of the squares of only the even numbers in nums, in one list comprehension combining a filter and a transform.

Examples

Example 1
Input
even_squares([1, 2, 3, 4])
Output
[4, 16]
Explanation

Only 2 and 4 are even; their squares are 4 and 16.

Constraints

  • Use a single list comprehension.
  • Preserve original order.

Topics

List Comprehensionsfilter + map

Companies

TCSInfosysWipro

Hints

Hint 1

The if clause goes after the for clause.

Hint 2

[n * n for n in nums if ...].

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.