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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access