Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Chain map and filter to square even numbers

Filter even numbers and then square them by chaining filter and map with lambdas.

Python practice15 minFunctions as Objects (Lambda, Map/Filter)IntermediateLast updated March 20, 2026

Problem statement

Create a function square_even_numbers(numbers) that accepts an iterable of integers and returns a list of the squares of the even numbers, preserving the original order. Implement this by first using filter(...) with a lambda to keep even numbers, then using map(...) with a lambda to square them, and finally converting the result to a list.

Task

Combine filter and map with lambda functions to process a sequence: select evens then transform them.

Examples

Mix of numbers

Input

[1, 2, 3, 4, 0, -2]

Output

[4, 16, 0, 4]

Evens are 2,4,0,-2. Their squares are 4,16,0,4 in the same order.

Input format

A single argument: an iterable (e.g., list or tuple) of integers.

Output format

A list of integers (squares of even inputs) in the same relative order as the even numbers in the input.

Constraints

Use filter(...) and map(...) with lambda expressions. Preserve order. The function should accept any iterable, not just lists.

Samples

Sample 1

Input

[1,3,5,7]

Output

[]

No even numbers, so result is an empty list.