On 7 Nov 2013 03:18, "Antoine Pitrou" <solip...@pitrou.net> wrote:
>
> Le 06/11/2013 06:41, Nick Coghlan a écrit :
>
>>
>> The behaviour of mutating builtin containers while iterating over them
>> is formally undefined beyond "it won't segfault" (one of the few such
>> undefined behaviours in Python). The associated exceptions are thus
>> strictly "best effort given other constraints".
>
>
> Not sure what you mean with "formally undefined". For example, you can
perfectly well change a list's contents while iterating over it, and I bet
there's a lot of code that relies on that, as in::
>
> for i, value in enumerate(mylist):
>     if some_condition(value):
>         mylist[i] = some_function(value)
>
> If you change "builtin containers" to "builtin unordered containers",
then you probably are closer to the truth :)

I meant changing the length rather than just the contents of an existing
entry. Even lists get a little odd if you add and remove entries while
iterating (although I agree the sequence case is much better defined than
the unordered container case).

Cheers,
Nick.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to