Unexpected Behavior Iterating over a Mutating Object

Fredrik Lundh fredrik at pythonware.com
Wed Sep 14 08:11:06 CEST 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++) {


More information about the Python-list mailing list