Filter and Transform Pipeline
Given a list of numbers, use filter() to keep only the even numbers, then use map() to square each of them, and print the final result as a list.
What the problem means: this chains two higher-order functions together — first narrow the list down (filter), then transform what's left (map).
Approach: filter(lambda x: x % 2 == 0, numbers) keeps only even numbers; map(lambda x: x ** 2, ...) squares each of those; wrap the final result in list(...) to see the values.
Input: One line: space-separated whole numbers.
Output: One line: the squares of the even numbers, printed as a Python list, in their original order.
1 2 3 4 5 6
[4, 16, 36]
- 1 <= count of numbers <= 1000
Hint 1
filter(lambda x: x % 2 == 0, numbers) keeps only the numbers that satisfy the condition.
Hint 2
map(lambda x: x ** 2, ...) applies squaring to every remaining item.
Hint 3
Both filter() and map() return iterators — wrap the final result in list(...) before printing.
Chain the two higher-order functions: evens = filter(lambda x: x % 2 == 0, numbers) keeps only even values, then squared = map(lambda x: x ** 2, evens) transforms each surviving value. Wrapping the final map object in list(...) turns it into a real list ready to print.