On Thu, Mar 12, 2020 at 10:43 AM Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:

> What if a for loop, instead of nexting the iterator and binding the result
> to the loop variable, instead unbound the loop variable, nexted the
> Iterator, and bound the result to the loop variable? Presumably this would
> slow down all loops a very tiny bit (by the cost of checking whether a name
> is bound) but speed up some—and it would speed up this one even more than
> your explicit del could (because it doesn’t need an whole extra opcode to
> loop over, if nothing else). Maybe there’s a way a clever optimization in
> the compiler and/or interpreter could figure out when it is and isn’t worth
> doing?
>

For a "statement" for-loop this would change the semantics, since (even
though not everyone likes this behavior) Python currently requires that the
loop control variable retain the last value assigned to it. But in
comprehensions it might work, since the comprehension control variable
lives in an inner scope (at least if it's a simple variable).

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FUY6ZYUD5M6HRV26YY7C7WQSINOYGGCY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to