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, 12Create a
lambda function inside map() that squares each numberConvert the result of
map() to a list called squared_agesPrint 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