1.
map()
Purpose: Transform each element of a sequence using a function.
Input: function + iterable
Output: new iterable (with the same length, transformed values)
Example: Square every number in a list
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, numbers))
print(squared) # [1, 4, 9, 16, 25]
🔹 2. filter()
Purpose: Select elements from a sequence that satisfy a condition.
Input: function (returns True/False) + iterable
Output: new iterable (with fewer or equal elements)
Example: Keep only even numbers
numbers = [1, 2, 3, 4, 5]
evens = list(filter(lambda x: x % 2 == 0, numbers))
print(evens) # [2, 4]
🔹 3. reduce()
Purpose: Repeatedly apply a function to accumulate a result.
Input: function (with two arguments) + iterable
Output: single value
Example: Find the product of all numbers
from functools import reduce
numbers = [1, 2, 3, 4, 5]
product = reduce(lambda x, y: x * y, numbers)
print(product) # 120