Reducing involves taking a function and an iterable and producing a single result value.The functools module’s functools.reduce() function supports this.
If we only wanted to count the .py file sizes we can filter out non-Python files. Here are three ways to do this:
When we want to sort we can specify a key function. This function can be any function, for example, a lambda function, a built-in function or method (such as str.lower()), or a function returned by operator.attrgetter().
L.sort(key=operator.attrgetter("priority")).For example, although it is possible to iterate over two or more lists by concatenating them, an alternative is to use itertools.chain() like this:
for value in itertools.chain(data_list1, data_list2, data_list3):
total += valuePartial function application is the creation of a function from an existing function and some arguments to produce a new function that does what the original function did, but with some arguments fixed so that callers don’t have to pass them.
reader = functools.partial(open, mode="rt", encoding="utf8")
writer = functools.partial(open, mode="wt", encoding="utf8")In Python, a coroutine is a function that takes its input from a yield expression.
Coroutines are useful when we want to apply multiple functions to the same pieces of data, or when we want to create data processing pipelines, or when we want to have a master function with slave functions. Coroutines can also be used to provide simpler and lower-overhead alternatives to threading.
Figure 8.3 A three-step coroutine pipeline processing six items of data









