from itertools import takewhile from itertools import count def count_up(start, step, stop): return takewhile(lambda x: x < stop, count(start, step)) print list(count_up(1, 3, 10)) # >>[1, 4, 7] print list(count_up(1, 6, 30)) # >>[1, 7, 13, 19, 25]
https://gist.github.com/aminami1127/2e92331b71fedc1b6d47
By useing itertools.takewhile and itertools.count, it’s easy to create counter function. cool!