yet another "groupsofn" function (newbie entertainment)

David Isaac aisaac0 at
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)
    for k,it in groupby(itr,lambda
        yield tuple(y for y in it)

More information about the Python-list mailing list