Skip to content

Instantly share code, notes, and snippets.

@icio icio/groupn.py

Created Jul 16, 2014
Embed
What would you like to do?
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
You can’t perform that action at this time.