Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 827 Bytes

File metadata and controls

38 lines (33 loc) · 827 Bytes
>>> import itertools

# Except for being infinite, the standard version returns the same # results as the range function does. >>> for a, b in zip(range(3), itertools.count()): ... a, b (0, 0) (1, 1) (2, 2)

# With a different starting point the results are still the same >>> for a, b in zip(range(5, 8), itertools.count(5)): ... a, b (5, 5) (6, 6) (7, 7)

# And a different step works the same as well >>> for a, b in zip(range(5, 10, 2), itertools.count(5, 2)): ... a, b (5, 5) (7, 7) (9, 9)

# Unless you try to use floating point numbers >>> range(5, 10, 0.5) Traceback (most recent call last):

...

TypeError: 'float' object cannot be interpreted as an integer

# Which does work for count >>> for a, b in zip(range(5, 10), itertools.count(5, 0.5)): ... a, b (5, 5) (6, 5.5) (7, 6.0) (8, 6.5) (9, 7.0)