Output:
[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.
Claim your Free $5 Bonus Here:https://bit.ly/3wUxw09LinkedIn profile ๐https://www.linkedin.com/in/subarno-roy-3b2251374Join our WhatsApp Channel ๐
https://whatsapp.com/channel/0029VbAi27y0lwghBe9mE42iWhatsApp Community Link ๐https://chat.whatsapp.com/HPJDqRr6G1sKQIqfdJF3pL1๏ธโฃ
Big Data๐ Channel Link:
[
https://t.me/bigdataofficial ]
---
2๏ธโฃ
Machine Learning๐ Channel Link:
[
https://t.me/machinelearningofficial ]
---
3๏ธโฃ
Cloud Computing๐ Channel Link:
[
https://t.me/cloudcomputing_official ]
---
4๏ธโฃ
Python๐ Channel Link:
[
https://t.me/python_programming_resources ]
Share with your College Whatsapp Groups & Friends tooAll the best ๐๐