[Python-bugs-list] Iterator doesn't re-evaluate with a dynamically (PR#179)

seanj@speakeasy.org seanj@speakeasy.org
Wed, 12 Jan 2000 00:18:55 -0500 (EST)


Yes, that is the behaviour I was looking for. Thank You. I guess the bug can be
resolved RTFM. But it should still work the way I want it! B^)

I achieved the same result with the code below, after accounting for the array
compaction.

Is the temporary copy l_sync[:] as expensive as a deepcopy?

i = 0;
while (i != len(l_sync)):
        x = l_sync[0]
        if x[0] == '#':
                print(x)
                if x[0:2] != '#d':
                        del l_sync[i]
                else:
                        i = i + 1

On Tue, 11 Jan 2000, Tim Peters wrote:

> [Sean Jensen-Grey, mutating a list while iterating over it]
> > ...
> > # is this expected behavior?
> 
> Yes indeed.  See the Language Reference Manual, section "The 'for'
> statement".
> 
> Change, e.g.,
> 
>     for x in l_sync:
> 
> to
> 
>     for x in l_sync[:]:
> 
> if that's not the behavior you want.
> 
>