0
0
Pythonprogramming~15 mins

Lambda with map() in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Lambda with map() to Square Numbers
๐Ÿ“– Scenario: Imagine you have a list of numbers representing the ages of children in a class. You want to find the square of each age to understand how their growth might be represented in a fun math exercise.
๐ŸŽฏ Goal: You will create a list of ages, then use a lambda function with map() to calculate the square of each age, and finally print the list of squared ages.
๐Ÿ“‹ What You'll Learn
Create a list called ages with the exact values: 5, 7, 9, 10, 12
Create a lambda function inside map() that squares each number
Convert the result of map() to a list called squared_ages
Print the squared_ages list
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Using lambda with map() helps quickly apply simple changes to lists of data, like adjusting prices, converting units, or processing user inputs.
๐Ÿ’ผ Career
Many programming jobs require processing lists of data efficiently. Knowing how to use lambda with map() is a handy skill for data cleaning, transformation, and automation.
Progress0 / 4 steps
1
Create the list of ages
Create a list called ages with these exact values: 5, 7, 9, 10, 12
Python
Need a hint?

Use square brackets [] to create a list and separate numbers with commas.

2
Set up the lambda with map()
Create a variable called squared_ages that uses map() with a lambda function to square each number in the ages list
Python
Need a hint?

The lambda function takes one input x and returns x * x. Use list() to convert the map object to a list.

3
Print the squared ages
Write a print() statement to display the squared_ages list
Python
Need a hint?

Use print(squared_ages) to show the list of squared numbers.

4
Explain the output
Add a print() statement that prints the text "Squared ages:" followed by the squared_ages list using an f-string
Python
Need a hint?

Use print(f"Squared ages: {squared_ages}") to combine text and the list in one line.