ch11-24: clean up by @eumiro & sync with Atlas
This commit is contained in:
11
17-it-generator/aritprog_v3.py
Normal file
11
17-it-generator/aritprog_v3.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# tag::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[]
|
||||
Reference in New Issue
Block a user