[Python-ideas] Assignments in list/generator expressions

Georg Brandl g.brandl at gmx.net
Tue Apr 12 08:31:52 CEST 2011


On 12.04.2011 07:06, Nick Coghlan wrote:
> On Tue, Apr 12, 2011 at 1:53 PM, Carl M. Johnson
> <cmjohnson.mailinglist at gmail.com> wrote:
>> On Mon, Apr 11, 2011 at 2:14 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>>
>>>  ys = [y for x in xs letting y = f(x) if y]
>>
>> Isn't that ambiguous? What if someone used the conditional expression:
>> ys = [y for x in xs letting y = f(x) if y else g(x)] ? It seems like
>> the letting/given has to go last in order to eliminate the possible
>> ambiguity in the subsequent optional if clause.
> 
> given/as resolves the parsing ambiguity problem by putting the names second:
> 
> ys = [y for x in xs given f(x) if p(x) else g(x) as y]

Is it just me, or do others find this "string of clauses" (no matter what
the actual keywords are) not very readable?

Georg




More information about the Python-ideas mailing list