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 lessonUse 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
- Filter Out Short WordsBeginner
- Predict the Pipeline OutputBeginner
- Fix the Broken PipelineIntermediate
- Find the Product with reduce()Intermediate
- Build a Data PipelineAdvanced
- Refactor to a List ComprehensionAdvanced
All Python exercises · 50 practice problems · Functions quiz