Python Learning Series · @onlysamarrr · Day 22 / 30
Day 22 teaches lambda, map and filter. lambda is a small one-line function without a name, map() runs a function on every item, and filter() keeps only items that pass a condition.
Phase: Intermediate · Reels: 106/450 – 110/450
Day 22 teaches lambda, map and filter. lambda is a small one-line function without a name, map() runs a function on every item, and filter() keeps only items that pass a condition.
double = lambda x: x * 2 print(double(5)) prices = [100, 250, 400] off = list(map(lambda p: p * 0.9, prices)) print(off) ev = list(filter(lambda n: n % 2 == 0, range(7))) print(ev) names = ["Al", "Riya", "Arhan"] print(sorted(names, key=len))
10 [90.0, 225.0, 360.0] [0, 2, 4, 6] ['Al', 'Riya', 'Arhan']
Discounts, data cleaning and sorting by a custom rule use map, filter and key functions.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. What is lambda x: x * 2?
Q2. What does map() do?
Q3. What does filter() keep?
| 106/450 | Concept | lambda function |
| 107/450 | Live demo | map aur filter demo |
| 108/450 | Common mistake | lambda ko overuse mat karo |
| 109/450 | Quiz | Quiz: even numbers filter |
| 110/450 | Interview / real life | Real life: prices pe discount |