TGViewer
App Development App Development @appdevelopment_official ยท 361 subscribers
Post #317 125
๐Ÿš€ Data Science Roadmap 2026

๐Ÿ“˜ Phase 1: Programming Fundamentals

๐Ÿ Topic 9: Python Lambda Functions, map(), filter(), and reduce()

Welcome back! ๐Ÿ‘‹

So far, you've learned Python basics, loops, functions, data structures, and list comprehensions. In this lesson, you'll learn functional programming concepts in Python using Lambda Functions, map(), filter(), and reduce().

These are widely used in Data Science for transforming, filtering, and processing large datasets efficiently.

๐Ÿ”น 1. What is a Lambda Function?

A Lambda Function is a small anonymous function that can have any number of arguments but only one expression.

Unlike normal functions, lambda functions don't require a name.

Syntax

lambda arguments: expression

Example

square = lambda x: x * x
print(square(5))

Output: 25

This is equivalent to:

def square(x):
return x * x

๐Ÿ”น 2. Why Use Lambda Functions?

Lambda functions are useful when:

โœ… You need a simple function only once.

โœ… You want shorter, cleaner code.

โœ… You're using functions like map(), filter(), or sorted().

๐Ÿ”น 3. Lambda with Multiple Arguments

add = lambda a, b: a + b
print(add(10, 20))

Output: 30

๐Ÿ”น 4. The map() Function

The map() function applies a function to every item in an iterable.

Syntax: map(function, iterable)

Example

numbers = [1, 2, 3, 4, 5]

squares = list(map(lambda x: x ** 2, numbers))
print(squares)

Output: [1, 4, 9, 16, 25]

๐Ÿ”น 5. Using map() with a Normal Function

def double(x):
return x * 2

numbers = [1, 2, 3, 4]
result = list(map(double, numbers))
print(result)

Output: [2, 4, 6, 8]

๐Ÿ”น 6. The filter() Function

The filter() function selects only those elements that satisfy a condition.

Syntax: filter(function, iterable)

Example

numbers = [1, 2, 3, 4, 5, 6]

even = list(filter(lambda x: x % 2 == 0, numbers))

print(even)

Output: [2, 4, 6]

๐Ÿ”น 7. The reduce() Function

The reduce() function applies a function repeatedly to reduce an iterable to a single value.

It is available in the functools module.

from functools import reduce
numbers = [1, 2, 3, 4]
result = reduce(lambda a, b: a + b, numbers)
print(result)

Output: 10

๐Ÿ”น 8. Difference Between map(), filter(), and reduce()

map(): Transforms every element in an iterable and returns a new iterable.

filter(): Keeps only elements that match a condition and returns a filtered iterable.

reduce(): Combines all elements into a single value.

๐Ÿ”น 9. Real-World Data Science Example

Suppose you have customer purchase amounts.

purchases = [1200, 450, 1800, 900, 2500]
high_value = list(filter(lambda x: x > 1000, purchases))
print(high_value)

Output: [1200, 1800, 2500]

Now calculate the total revenue.

from functools import reduce
total = reduce(lambda a, b: a + b, purchases)
print(total)

Output: 6850

๐Ÿ”น 10. Combining map() and filter()

numbers = [1, 2, 3, 4, 5, 6]
result = list(
map(
lambda x: x * 10,
filter(lambda x: x % 2 == 0, numbers)
)
)
print(result)


Claim your Free $5 Bonus Here:
https://bit.ly/3wUxw09

LinkedIn profile ๐Ÿ‘‡

https://www.linkedin.com/in/subarno-roy-3b2251374

Join our WhatsApp Channel ๐Ÿ‘‡

https://whatsapp.com/channel/0029VbAi27y0lwghBe9mE42i

WhatsApp Community Link ๐Ÿ‘‡

https://chat.whatsapp.com/HPJDqRr6G1sKQIqfdJF3pL

1๏ธโƒฃ Web Development and Web Design
๐Ÿ“Ž Channel Link:
[ https://t.me/webdevelopmentandwebdesigning ]

---

2๏ธโƒฃ Programming Books
๐Ÿ“Ž Channel Link:
[ https://t.me/programmingbooks_official ]

---

3๏ธโƒฃ Android Development
๐Ÿ“Ž Channel Link:
[ https://t.me/androiddevelopment_official ]

---

4๏ธโƒฃ App Development
๐Ÿ“Ž Channel Link:
[ https://t.me/appdevelopment_official ]

---

5๏ธโƒฃ Digital Marketing
๐Ÿ“Ž Channel Link:
[ https://t.me/digitalmarketing_official ]

Share with your College Whatsapp Groups & Friends too

All the best ๐Ÿ‘๐Ÿ‘
More from @appdevelopment_official
  1. Oct 8, 2026INDIA'S BIGGEST SHOPPING SALE IS LIVE TOMORROW IS IT REALLY A DEAL๐Ÿคก? THIS APP BUYHATKE TEโ€ฆ
  2. Oct 3, 2026๐—ง๐—ต๐—ผ๐˜€๐—ฒ ๐˜„๐—ต๐—ผ ๐˜„๐—ฎ๐—ป๐˜ ๐—ฟ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฟ๐—ฎ๐—น๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—๐—ผ๐—ฏ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ป๐˜€๐—ต๐—ถ๐—ฝ๏ฟฝโ€ฆ
  3. Sep 30, 2026โค๏ธ Here is the list of highly recommended Telegram channels for your free learning โค๏ธ Getโ€ฆ
  4. Sep 27, 2026๐Ÿšจ Earn Passive Money Easily ๐Ÿšจ Since your device is already connected to the internet, yoโ€ฆ
  5. Sep 26, 2026Hackathon National Research & Innovation Challenge Season 3 ๐Ÿ“ŒAPPLY LINK : https://bit.ly/โ€ฆ
  6. Sep 11, 2026๐—ง๐—ต๐—ผ๐˜€๐—ฒ ๐˜„๐—ต๐—ผ ๐˜„๐—ฎ๐—ป๐˜ ๐—ฟ๐—ฒ๐—ณ๐—ฒ๐—ฟ๐—ฟ๐—ฎ๐—น๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—๐—ผ๐—ฏ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ป๐˜€๐—ต๐—ถ๐—ฝ๏ฟฝโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’