[Tutor] How to iterate and update subseqent items in list

Remco Gerlich remco at gerlich.nl
Thu Dec 6 15:58:20 CET 2007


Hi,

In this case, I'd go for the simple old fashioned for loop with a boolean:

found = False
for thing in Things:
    if thing.value > 0:
        found = True
    if found:
        thing.value = 2

Remco Gerlich

On Dec 6, 2007 9:48 AM, ted b <phpmoonlighter at yahoo.com> wrote:

> Can you suggest a good way to iterate through the
> remainder of list and update them?
>
> Ex:
> Thing1.value = 0
> Thing2.value = 1
> Thing3.value = 0
> Thing4.value = 0
>
> Things = [Thing1, Thing2, Thing3, Thing4]
>
> I want to iterate through 'Things' and if
> 'Thing.value' > 0, then I want to set all values for
> that and the subsequent 'Things' in the list to 2
>
> So that i'd end up with
>
> Thing1.value = 0
> Thing2.value = 2
> Thing3.value = 2
> Thing4.value = 2
>
>
>
>  ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071206/fde1f23b/attachment.htm 


More information about the Tutor mailing list