Skip to content

Instantly share code, notes, and snippets.

@HarkonenBade
Forked from cillian64/enum_step.py
Last active February 20, 2016 23:25
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 HarkonenBade/32f513b0a8329eb41d36 to your computer and use it in GitHub Desktop.
Save HarkonenBade/32f513b0a8329eb41d36 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):
...
"""
for i, x in enumerate(seq):
yield (start + (i*step), x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment