[portland] Need Help With a For Loop

Dylan Reinhardt python at dylanreinhardt.com
Thu Mar 20 20:10:10 CET 2008


On 3/20/08, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>
>
>    The behavior I want, in pseudocode is this:
>
>    For each parent:
>      hold plot axes until done
>      use curve #1 and call appropriate plotting function
>      increment curve number (which, I believe) the for loop does
>         automatically)
>      use next curve and call appropriate plotting function


Your problem is that you're running the loop once for each item in your
collection, but appear to be operating on the same element each time through
the loop.  It is true that your index will increment, but then if you don't
use the index to acquire your next element, the fact that it increments is
of no use.

In most cases, I would strongly recommend ditching this idiom:

for i in range(len(collection)):
    doSomething(collection[i])

In favor of this one:

for item in collection:
    doSomething(item)

HTH,

Dylan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/portland/attachments/20080320/f6c1a2c5/attachment.htm 


More information about the Portland mailing list