Nested lists or conditional logic?
tjreedy at udel.edu
Wed Jan 28 21:10:39 CET 2004
"mike beck" <cmichaelbeck at hotmail.com> wrote in message
news:ead93a6.0401280956.41fd4193 at posting.google.com...
> this is not all complex, but as a noob i'm having a hard time getting
> my head around it.
> i have a list of items. i need to print the items in batches of x,
> with a summary line after each complete or partial batch, and a total
> line at the end of the job.
> i've done the following, which works, but it seems like there must be
> a better/simpler/faster way to do this with nested loops. ideas?
The awkwardness is inherent in having non-0 remainders. An explicit
counter strikes me as both simple and fast. Maybe because what you did is
exactly the way I have done similar things. But I would probably make
print_summary a function to avoid duplicating code in two places.
Terry J. Reedy
More information about the Python-list