Skip to content

Instantly share code, notes, and snippets.

@icio
Created July 16, 2014 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icio/aa6a6aa2bf2fb451d320 to your computer and use it in GitHub Desktop.
Save icio/aa6a6aa2bf2fb451d320 to your computer and use it in GitHub Desktop.
from itertools import groupby, count
def debug_iter(iter):
for x in iter:
print "=> %d" % x
yield x
def groupn(n, it):
c = count()
return ((g, sit) for g, sit in groupby(it, key=lambda x: c.next() // n))
for g, sit in groupn(5, debug_iter(xrange(20))):
for s in sit:
print g, s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment