Skip to content

Instantly share code, notes, and snippets.

@aminami1127
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aminami1127/2e92331b71fedc1b6d47 to your computer and use it in GitHub Desktop.
Save aminami1127/2e92331b71fedc1b6d47 to your computer and use it in GitHub Desktop.
itertools.takewhile
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]
@aminami1127
Copy link
Author

By useing itertools.takewhile and itertools.count, it’s easy to create counter function. cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment