yet another "groupsofn" function (newbie entertainment)

David Isaac aisaac0 at verizon.net
Thu Oct 5 03:30:22 CEST 2006


I have not seen this posted and I kind of like it.
Shared for entertainment value only.
Alan Isaac
PS Easily adapted if the residual
group is not desired.

def groupsofsize(iterable,size):
    itr = iter(iterable)
    c=count()
    for k,it in groupby(itr,lambda x:c.next()//size):
        yield tuple(y for y in it)





More information about the Python-list mailing list