A function which accepts a function as an argument, or returns a function as a result, is called a higher-order function. Python has a number of higher-order functions. The most commonly-used of these functions are
itertools module contains numerous additional higher-order functions.
filter() functions are generators; their results must be consumed. Both of them apply a function to a collection of values. In the case of
map(), the results of the function are yielded. In the case of
filter(), if the result of the function is true, the original value is yielded.
Here's how we can apply a very simple function—so simple we coded it as a lambda—to a sequence of values: ...