Counting nested loop iterations
Derek Basch
dbasch at yahoo.com
Thu Mar 16 15:34:33 EST 2006
Fredrik Lundh wrote:
> what's kludgy with using a counter to count things ?
Ohhh, nothing in particular. Just seeing if there is a better way to do
it.
> (the real question here is of course why you need the counter. what's
> the loop doing? if the code you posted is all you have, you can replace
> it with index = sum(len(animal) for animal in zoo), but I assume you want
> to do more stuff in there...)
>
> </F>
Yes, I am doing more. Your example assumes that all that animals have
the same amount of colors. Not a bad assumption considering I didn't
say anything about that. Looks like good old counters are they way to
go then.
More information about the Python-list
mailing list