example-code-2e/iterables/aritprog_v3.py
2014-12-14 01:26:42 -02:00

12 lines
298 B
Python

# BEGIN ARITPROG_ITERTOOLS
import itertools
def aritprog_gen(begin, step, end=None):
first = type(begin + step)(begin)
ap_gen = itertools.count(first, step)
if end is not None:
ap_gen = itertools.takewhile(lambda n: n < end, ap_gen)
return ap_gen
# END ARITPROG_ITERTOOLS