Last active
August 29, 2015 14:14
-
-
Save aminami1127/2e92331b71fedc1b6d47 to your computer and use it in GitHub Desktop.
itertools.takewhile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By useing itertools.takewhile and itertools.count, it’s easy to create counter function. cool!