Editor

Filter and Transform

Intermediate · Write the code · from Python Lambda Functions: When to Use (and When Not To)

From the lesson: Python Lambda Functions: When to Use (and When Not To)

Imagine you need to leave someone a quick note: "Back in 5 minutes." You wouldn't write a formal letter with a greeting, three paragraphs, and a signature. You'd scribble it on a sticky note and be done.

Read the lesson

Given a list of numbers, use filter() with a lambda to keep only numbers greater than 10, then use map() with a lambda to square each remaining number. Print the final list.

Use this list: numbers = [3, 15, 7, 20, 8, 12]

Expected output: [225, 400, 144]

numbers = [3, 15, 7, 20, 8, 12]
# Filter numbers > 10, then square them

More Lambda exercises

All Python exercises · 50 practice problems · Functions quiz