[Python-Dev] Examples for PEP 572

Serhiy Storchaka storchaka at gmail.com
Wed Jul 4 03:58:48 EDT 2018


04.07.18 05:42, Steven D'Aprano пише:
> On Tue, Jul 03, 2018 at 09:54:22PM -0400, Terry Reedy wrote:
>>>      results = [(x, y, x/y) for x in input_data for y in [f(x)] if y > 0]
>>
>> Would (f(x),) be faster?
> 
> There is a deferred feature request to optimize "for x in [item]" as
> equivalent to "for x in (item,)", to avoid constructing a list:
> 
> https://bugs.python.org/issue32856

No, this optimization was already made in issue32925. Issue32856 is a 
different optimization -- it makes such constructions be as fast as a 
simple assignment. It allows to use an assignment in comprehensions 
without introducing a new syntax and with zero overhead.



More information about the Python-Dev mailing list