Skip to content

Instantly share code, notes, and snippets.

@adeel
Created May 24, 2011 03:38
Show Gist options
  • Save adeel/988105 to your computer and use it in GitHub Desktop.
Save adeel/988105 to your computer and use it in GitHub Desktop.
def iterate_in_steps(seq, n, increment):
if len(seq) >= n:
return [tuple(seq[:n])] + iterate_in_steps(seq[increment:], n, increment)
else:
return []
# >>> iterate_in_steps([1, 2, 3, 4, 5], 2, 1)
# [(1, 2), (2, 3), (3, 4), (4, 5)]
#
# >>> iterate_in_steps([1, 2, 3, 4, 5], 3, 2)
# [(1, 2, 3), (3, 4, 5)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment