better way to write this function

Paul Rubin http
Mon Nov 26 03:51:23 EST 2007


Chris <cwitts at gmail.com> writes:
>     for i in range(int(round((len(lst)/n),0))): ...

Ugh!!!  Not even correct (under future division), besides being ugly.
I think you mean:

   for i in xrange(len(lst) // n): ...

Really though, this grouping function gets reimplemented so often that
it should be built into the stdlib, maybe in itertools.



More information about the Python-list mailing list