Printing n elements per line in a list

Paul Rubin http
Tue Aug 15 20:39:46 EDT 2006


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.



More information about the Python-list mailing list