Editor

Square Every Number

Beginner · Write the code · from Python map(), filter(), reduce(), and Higher-Order Functions

From the lesson: Python map(), filter(), reduce(), and Higher-Order Functions

Picture an assembly line in a factory. Raw materials enter at one end. At the first station, each piece is shaped. At the next station, defective pieces are removed. At the final station, all the good pieces are combined into one finished product.

Read the lesson

Use map() with a lambda to square every number in the list [1, 2, 3, 4, 5].

Print the result as a list.

Expected output:

[1, 4, 9, 16, 25]
numbers = [1, 2, 3, 4, 5]
# Use map() to square each number

More Map, Filter and Reduce exercises

All Python exercises · 50 practice problems · Functions quiz