Skip to Content
Practical Time Series Analysis
book

Practical Time Series Analysis

by PKS Prakash, Avishek Pal
September 2017
Beginner
244 pages
5h 20m
English
Packt Publishing
Content preview from Practical Time Series Analysis

Iterators

Objects that are instances of classes that have __iter__ and next functions and can be used with a for loop to go over a sequence element by element are iterators. The __iter__ function makes an object recognizable as an iterator. The next function is invoked to get the elements of a sequence one by one. Every time the next function is called, it returns an element from the predefined sequence or it creates an element. Hence, the next function can implement the logic to create the elements. When there are no more elements, the __next__ function throws a StopIteration error.

Let's go through examples to understand how iterators work. We create an iterator to return elements from a predefined sequence:

class MyIterator(object):def ...
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.
Start your free trial

You might also like

Practical Time Series Analysis

Practical Time Series Analysis

Aileen Nielsen

Publisher Resources

ISBN: 9781788290227Supplemental Content