A lambda is a small, unnamed function written in a single line — useful when you need a quick throwaway function and don't want to write a full def block for it. Lambdas are most commonly paired with three functional-programming tools: map() (transform every item), filter() (keep only some items), and reduce() (combine everything into one value).

map() — Transform Every Item in a List

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

squared = list(map(lambda x: x ** 2, numbers))
print(f"Squared: {squared}")

Output:

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

filter() — Keep Only the Items That Match a Condition

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

evens = list(filter(lambda x: x % 2 == 0, numbers))
print(f"Evens: {evens}")

Output:

Evens: [2, 4, 6, 8, 10]

reduce() — Combine Every Item into One Value

reduce() isn't a built-in like the other two — it lives in the functools module and needs to be imported.

from functools import reduce

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

product = reduce(lambda acc, x: acc * x, numbers)
print(f"Product of all numbers: {product}")

Output:

Product of all numbers: 120

reduce() walks through the list applying the lambda two items at a time, carrying an accumulator (acc) forward: first 1 * 2 = 2, then 2 * 3 = 6, then 6 * 4 = 24, then 24 * 5 = 120. It's the same idea behind summing a list or finding a maximum value, generalized to any combining operation you give it.

In modern Python, a list comprehension can usually replace map()/filter() more readably — [x ** 2 for x in numbers] does the same job as the map() example above, and [x for x in numbers if x % 2 == 0] replaces the filter() example. reduce() doesn't have as clean a comprehension equivalent, so it still earns its place for genuine "combine everything into one result" problems.