Skip to content
← Python for AI/ML · all 50 levels

map & filter

Level 39 of 50 · Functions

Level 39 of 50

map & filter

explained with exam grace marks. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.

📒 Open the cheat sheet
SanaSir is giving 5 grace marks to the WHOLE class!
TeacherOne change for every item? That is map! And picking items? filter!
marks.py
marks = [40, 75, 90]
grace = lambda m: m + 5
up = map(grace, marks)
print(list(up))
Teachermap runs grace on every mark. Everyone gets +5!
SanaWhy wrap it in list?
Teachermap is lazy! list() makes it hand over all the results.
marks.py
marks = [40, 75, 90]
passed = lambda m: m >= 50
ok = filter(passed, marks)
print(list(ok))
Teacherfilter keeps only items where the test is True. 40 is out!

⏸ Pause & predict: what prints?

n = [5, 12, 8]
big = map(lambda x: x > 6, n)
print(list(big))

Where this leads

Python is step one. Building AI that ships is the rest.

The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.