Lambda Expressions

This is a small function with no name that contains an expression and returns its result. We will use it in the built in function filter: filter(function, iterable).

>>> numbers = [1,2,3,4,5,6,7,8,9,10]
>>> filter(lambda n: n % 2 == 0, numbers)
[2, 4, 6, 8, 10]
>>>

Tags: