Unexpected Behavior Iterating over a Mutating Object

Fredrik Lundh fredrik at pythonware.com
Wed Sep 14 02:11:06 EDT 2005


Dave Hansen wrote:

> Again, iterating over an item that is mutating seems like a Bad
> Idea(tm) to me.  But I was curious: is this the intended behavior, or
> does this fall under what C programmers would call 'undefined
> behavior.'

a C programmer wouldn't have much problem with this, of course,
since "for in" behaves like:

    for (tmp = 0; var = getitem(seq, tmp); tmp++) {
        ...
    }

</F>






More information about the Python-list mailing list