[20, 40, 60]
First, filter() keeps only even numbers.
Then, map() multiplies each by 10.
🔹 11. Common Mistakes
❌ Forgetting to Convert map() to a List
result = map(lambda x: x * 2, numbers)
→
<map object at ...>
Correct:
print(list(result))
❌ Forgetting to Import reduce()
result = reduce(lambda a, b: a + b, [1, 2, 3])
→
NameError
Correct:
from functools import reduce
🎯 Practice Questions
1. Create a lambda function that returns the cube of a number.
2. Use map() to convert a list of temperatures from Celsius to Fahrenheit.
3. Use filter() to find numbers greater than 50.
4. Use reduce() to calculate the product of a list of numbers.
5. Combine filter() and map() to square only the odd numbers in a list.
🎯 Key Takeaways
✅ Lambda functions are short, anonymous functions.
✅ map() transforms every element in an iterable.
✅ filter() selects elements based on a condition.
✅ reduce() combines all elements into a single value.
✅ These functions are widely used for data transformation, preprocessing, and feature engineering in Data Science.
Double Tap ❤️ For More