Posts Tagged ‘Itertools’

How to create an iterating counter in Python?

The itertools module provides a count generator that provides an iterating counter. import itertools   # Create a counter starting at 10 counter = itertools.count(10)   # Print numbers 10, 11, 12, … 20 for i in counter: print i if i==20: break From Python 2.7 the count generator also provides a step parameter. import [...]