Q50: How do map(), filter(), and functools.reduce() operate?

  • map(fn, iterable): Applies fn to every item, returning a lazy iterator.
  • filter(fn, iterable): Filters elements where fn(item) evaluates truthy, returning a lazy iterator.
  • reduce(fn, iterable): Accumulates elements sequentially into a single aggregate result.
Key Takeaways
  • map and filter return lazy iterators.
  • reduce aggregates sequence items down to a single value.
Knowledge Check

In which module does the reduce() function reside in Python 3?