[Python-ideas] An alternative to PEP 572's Statement-Local Name Bindings

Chris Angelico rosuav at gmail.com
Sun Mar 4 22:45:21 EST 2018


On Mon, Mar 5, 2018 at 2:39 PM, Mike Miller <python-ideas at mgmiller.net> wrote:
>
> On 2018-03-03 16:51, Greg Ewing wrote:
>>>
>>> 2018-03-03 8:40 GMT+01:00 Nick Coghlan <ncoghlan at gmail.com>:
>>>>
>>>>    pairs = [(f(y), g(y)) for x in things with bind(h(x)) as y]
>>
>>
>> I don't mucn like "with bind(h(x)) as y" because it's kind of
>> like an abstraction inversion -- you're building something
>> complicated on top of something complicated in order to get
>> something simple, instead of just having the simple thing
>> to begin with. If nothing else, it has a huge runtime cost
>> for the benefit it gives.
>
>
> Reading this thread I was thinking that the assignment part was happening
> too far away from where the action was and came up with this variant:
>
>     [ f(y), g(y) for x, y as h(x) in things ]
>
> Plus or minus an extra set of parentheses for clarity.

Did you mean:

[ f(y), g(y) for x, h(x) as y in things ]

? Elsewhere in Python, "a as b" takes "a" and binds it to the name
"b". Otherwise, I'm not sure what you meant.

ChrisA


More information about the Python-ideas mailing list