Created
July 16, 2014 16:28
-
-
Save icio/aa6a6aa2bf2fb451d320 to your computer and use it in GitHub Desktop.
This file contains 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
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