November 2022
Beginner to intermediate
752 pages
19h 19m
English
In the previous chapter, we escaped all the headaches of traditional index-based loops. However, we haven’t yet completely escaped the nested loop.
The solution is to employ generator expressions, which allow you to rewrite the entire logic of a loop in a single statement. You can even create lists in this manner, with the much-loved list comprehensions. Before I get there, I’ll introduce generators, which provide a more compact alternative to custom iterable classes in many situations. You’ll also encounter the oft-overshadowed cousin of the generator, the humble simple coroutine, which provides an iterative ...
Read now
Unlock full access