Now we come on to generator functions, one of the most powerful and elegant features of the Python programming language. Python generators provide the means for describing iterable series with code in functions. These sequences are evaluated lazily, meaning they only compute the next value on demand. This important property allows them to model infinite sequences of values with no definite end, such as streams of data from a sensor or active log files. By carefully designing generator functions we can make generic stream processing elements which can be composed into sophisticated pipelines.
Generator functions
The yield keyword
Generators are defined by any Python function which uses the yield keyword at least once in its...