Python · The language, not just syntax

How do map, filter and reduce compare with comprehensions?

MediumfunctionalmapreduceUpdated Oct 2026
Quiz this track

Short answer

map and filter return lazy iterators in Python 3, while reduce folds an iterable into one value. Comprehensions are usually more readable for transforms and filters; reduce is best reserved for genuine folds.

map applies a function to each item, filter keeps items where a predicate is true, and functools.reduce repeatedly combines values with a two-argument function. All three express operations over iterables, but Python style generally favours comprehensions for the first two.

python
from functools import reduce
from operator import add, mul

values = [1, 2, 3, 4]

doubled = list(map(lambda value: value * 2, values))
even = list(filter(lambda value: value % 2 == 0, values))
product = reduce(mul, values, 1)
total = reduce(add, values, 0)

print(doubled, even, product, total)
map and filter are lazy, so list materialises them. The initial value passed to reduce avoids an empty-sequence error.

Choosing the clearer form

  • Use [fn(x) for x in items] over map when the transform is simple
  • Use [x for x in items if pred(x)] over filter for the same reason
  • Use map with an existing named function when it reads more directly
  • Use reduce only for associative folds such as sum, product or flattening

Chained map and filter calls with lambdas quickly become harder to read than one comprehension, and a comprehension is often faster because it avoids repeated function calls. sum, any, all and max already cover most reductions without importing functools.

reduce with a non-associative operation can produce order-dependent results, especially if you later parallelise the work. Prefer an explicit loop when the fold needs side effects or early exit.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why do map and filter return iterators in Python 3?
  2. 2When is reduce clearer than a loop?
  3. 3What happens if reduce is called on an empty iterable without an initial value?
  4. 4Which built-ins replace common reduce use cases?

Say it in the interview

map and filter are lazy in Python 3 and return iterators, while reduce folds a sequence into one value. For simple transforms and filters I usually prefer a comprehension because it reads better and avoids lambda call overhead. I use map when there is already a named function, and reduce for genuine associative folds. Built-ins like sum and any cover most cases without importing functools.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Python mock interview and get scored feedback on depth, clarity and confidence.