Search notes:

Python: iterable

An iterable is an object that implements either
Well known examples of iterables are the sequence types list, tuple and str as well as the non-sequence type dict or file objects.
The elements that an instance of an iterable provides can be iterated over in statements or functions and statements such as
An iterable can be passed to iter which then returns an iterator for the iterable.
Iterators are a subset of iterables: they also have a __next__ method.

Basic operations

An iterable can be creted with the iter() built-in function.
The next item from an iterable is returned by the next() function.
list() creates a list from an iterable.
lst = [ 'one', 'two', 'three', 'four', 'five' ]
itr = iter(lst)

one = next(itr)
rst = list(itr)

print(one)
#
#  one

print(type(rst))
#
#  <class 'list'>

print(rst)
#
#  ['two', 'three', 'four', 'five']
Github repository about-Python, path: /iterable/basic-operations.py

Index