Summary
In this chapter, we've seen a number of the advanced features of functions. We've looked at the essential generator expression and how this is used as part of a comprehension. A list
comprehension assembles a list
from the generated values. Similarly, a set
comprehension creates a set
. A dictionary comprehension creates a dict
structure from the keys and values in a generator expression.
We've looked at using the yield
statement to create a generator function. This allows us to use all of the various Python statement features when creating a generator. Since a generator is iterable, it works with a for
loop so that we can write a simple loop to process multiple values created by an iterator.
We've also looked at higher-order functions. These ...
Get Python Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.