Skip to content

Instantly share code, notes, and snippets.

@phizaz
Created June 17, 2016 04:12
Show Gist options
  • Save phizaz/e9d3e33b1d350de717a6681fadd88131 to your computer and use it in GitHub Desktop.
Save phizaz/e9d3e33b1d350de717a6681fadd88131 to your computer and use it in GitHub Desktop.
A sliding window implementation in python
def window_slide(iter, size=2):
mem = [None] * size
for i, each in enumerate(iter):
mem[i % size] = each
if i >= size - 1:
yield mem[(i + 1) % size:] + mem[:(i + 1) % size]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment