📘 Lesson · Lesson 81
Map, Filter, Reduce
Functional Tools
💡 At a Glance
map, filter and reduce apply a function to a whole list without writing loops — often used with lambda.
map() — transform each
Python
nums = [1, 2, 3, 4] squared = list(map(lambda x: x*x, nums)) print(squared)
[1, 4, 9, 16]
filter() — keep some
Python
nums = [1, 2, 3, 4, 5, 6] even = list(filter(lambda x: x % 2 == 0, nums)) print(even)
[2, 4, 6]
reduce() — combine to one
Python
from functools import reduce nums = [1, 2, 3, 4] total = reduce(lambda a, b: a + b, nums) print(total)
10
Summary
- map transforms each item, filter keeps matching items, reduce combines to one value.
- Often paired with lambda for short functions.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.