[Python-Dev] The `for y in [x]` idiom in comprehensions

Guido van Rossum guido at python.org
Sun Feb 25 12:19:07 EST 2018


On Sun, Feb 25, 2018 at 6:36 AM, Serhiy Storchaka <storchaka at gmail.com>
wrote:

> 23.02.18 19:30, Guido van Rossum пише:
>
>> I'm not saying anything new here, but since you asked specifically for my
>> opinion: I don't care for the idiom; it's never occurred to me before, and
>> it smells of cleverness. If I saw it in a code review I would probably ask
>> for a regular for-loop to make the code more maintainable.
>>
>> But if you say it's useful for some class of users and it would be more
>> useful if it was faster, I'm fine with the optimization. The optimization
>> is also clever, and here I appreciate cleverness!
>>
>
> Thank you. Given the contradictory relation of other core developers to
> this idiom, and small total effect of this optimization (since the problem
> solved by using this idiom is rarely occurred), I'm inclined to defer this
> optimization on to some time (months or years). Maybe something will be
> changed during this period: either this idiom will become more popular, or
> new arguments against using it will be found, or better solution will be
> found, or this optimization will become the part of more general
> optimization.
>

Yeah, it doesn't seem there's any hurry. Opinions on the idiom are
definitely, um, divided. :-)

FWIW I don't care much about the 'f(x) as y' solution either, and being new
syntax it has a much higher bar.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180225/e7c32b96/attachment.html>


More information about the Python-Dev mailing list