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

Iterables

Objects that do not have the __iter__ or next function but can be used to create an iterator are iterables. The built-in __iter__ function takes a sequential object as input and returns an iterator. Then, another built-in function, next, takes the iterator and returns the iterator's elements in every invocation. Lists and tuples are not iterators but can be used to create iterators using the next function. The following code snippet demonstrates using a list as an iterator:

mylist = [1,2,3,4]mylist_iter = iter(mylist)print(type(mylist))print(type(mylist_iter))<class 'list'><class 'list_iterator'>

Notice that mylist is of type list while mylist_iter, which is created by the iter function, is of type list_iterator.

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