Paul Rubin <http://phr.cx@NOSPAM.invalid> writes: > for x,y in itertools.groupby(a, lambda n: n//5): > print ' '.join(str(k) for k in y) > > I hope I got that right. Of course I meant to say > for x,y in itertools.groupby(enumerate(a), lambda (n,x): n//5): > print ' '.join(str(k) for n,k in y) This is still way ugly and I've never found a really good solution.