Tsallaka zuwa abun ciki
Justice Tech School

lambda, map, filter

lambda makes small anonymous functions. map transforms and filter selects. Comprehensions are often clearer.

Example
sq = lambda x: x * x
print(sq(4))
print(list(map(str, [1, 2])), list(filter(lambda n: n > 1, [1, 2, 3])))

Result

16
['1', '2'] [2, 3]

Exercise

Anonymous function.

 x: x + 1

Quiz Test

What does filter do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.