10.1 Function tools
We looked at a number of higher-order functions in Chapter 5, Higher-Order Functions. Those functions either accept a function as an argument or return a function (or generator expression) as a result. All those higher-order functions have an essential algorithm that is customized by injecting another function. Functions such as max()
, min()
, and sorted()
accept a key=
function to customize their behavior. Functions such as map()
and filter()
accept a function and an iterable and apply the given function to the argument iterable. In the case of the map()
function, the results of the function are simply yielded. In the case of the filter()
function, the Boolean result of the function is used to yield or reject values from an iterable source.
All the functions in Chapter 5, Higher-Order Functions, are part of the Python __builtins__
package, meaning these functions are available without the need to use the import
statement. They were made ubiquitous because...