Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created February 8, 2015 10:03
Show Gist options
  • Save markrwilliams/8fa197b3b96d578de576 to your computer and use it in GitHub Desktop.
Save markrwilliams/8fa197b3b96d578de576 to your computer and use it in GitHub Desktop.
def nwise(iterable, n):
tees = itertools.tee(iterable, n)
for i, t in enumerate(tees):
for _ in xrange(i):
next(t)
return itertools.izip(*tees)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment