Skip to content

Instantly share code, notes, and snippets.

@cillian64
Created February 20, 2016 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cillian64/2df015c67ac05efce612 to your computer and use it in GitHub Desktop.
Save cillian64/2df015c67ac05efce612 to your computer and use it in GitHub Desktop.
enum_step
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