O'Reilly logo

Practical Time Series Analysis by Dr. PKS Prakash, Dr. Avishek Pal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generators

Generators give the functionality of iterators but without having to write an entire class. In many cases, the logic of creating the elements of a sequence are implemented in the next function of an iterator. For example, the code to read a text file line by line and return the occurrence of a specific word in each line needs to be written in the next function of an iterator. Other functions such as __init__ and __iter__ are implemented in the class merely to suffice the requirements of developing an iterator.

Generators are special functions that simplify development. The yield keyword in a function signals the Python interpreter that the function is a generator. Using generator functions, we implement only the logic of creating ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required