Created
October 31, 2012 02:30
-
-
Save fritz0705/3984465 to your computer and use it in GitHub Desktop.
window.py
This file contains hidden or 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 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