1 2 3 4 5 6 7
def regroup(l, n): """ Regroup list l by tuples of n elements >>> list(regroup([1,2,3,4,5,6,'EVIL_VALUE'], 3)) [[1, 2, 3], [4, 5, 6], ['EVIL_VALUE']] """ for i in xrange(0,len(l), n): yield l[i:i+n]