Tag Archives: itertools module

How to create classes of iterators using itertools module in Python

The itertools module provides iterators that you can use in your projects. One of the commonly used method is accumulate.

>>> import itertools
>>> accumulator = itertools.accumulate(range(10))
>>> next(accumulator)
0
>>> next(accumulator)
1
>>> next(accumulator)
3
>>> next(accumulator)
6
>>> next(accumulator)
10
>>> next(accumulator)
15

Continue reading