Created
February 20, 2016 23:12
-
-
Save cillian64/2df015c67ac05efce612 to your computer and use it in GitHub Desktop.
enum_step
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
def enum_step(seq, start=0, step=1): | |
""" | |
Like the builtin enumerate(seq), but with adjustable stepping. Useful for backwards enumeration: | |
for idx,x in enum_step(reversed(seq), len(seq)-1, -1): | |
... | |
""" | |
idx = start | |
for x in seq: | |
yield (idx, x) | |
idx += step |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment