Lesson 10
I am Your Father
Chapter 6: Higher order functions
Built-in higher order functions
In this chapter, we will look at two built-in higher-order functions map()
and filter()
. These functions are used a lot in functional-style programming.
Note that you can actually use list comprehensions to achieve the same thing with these two functions. In fact, the Python community generally prefers list comprehension because it makes the code more self-explanatory, especially for beginners.
In the following pages, I will present a list comprehension solution first, before presenting a solution using these higher-order functions. Compare them and see which you find more readable.