Skip to content

Instantly share code, notes, and snippets.

@fritz0705
Created October 31, 2012 02:30
Show Gist options
  • Save fritz0705/3984465 to your computer and use it in GitHub Desktop.
Save fritz0705/3984465 to your computer and use it in GitHub Desktop.
window.py
def window(iterable, size=2):
i = iter(iterable)
win = []
for e in range(0, size):
win.append(next(i))
yield win
for e in i:
win = win[1:] + [e]
yield win
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment