Counting nested loop iterations

Duncan Booth duncan.booth at invalid.invalid
Thu Mar 16 16:07:41 EST 2006


Derek Basch wrote:

> index = 0
> for animal in zoo:
>     for color in animal:
>         index += 1
          # assuming there is something more goes here...
> 

You could do this, but it kind of depends what the loop *really* looks 
like:

for index, color in enumerate(color
                              for animal in zoo
                              for color in animal):
    # the something more goes here.
    pass





More information about the Python-list mailing list