[Python-ideas] Assignments in list/generator expressions

Terry Reedy tjreedy at udel.edu
Tue Apr 12 18:09:00 CEST 2011


On 4/12/2011 2:31 AM, Georg Brandl wrote:
> On 12.04.2011 07:06, Nick Coghlan wrote:

>> ys = [y for x in xs given f(x) if p(x) else g(x) as y]
>
> Is it just me,

No.

> or do others find this "string of clauses" (no matter what
> the actual keywords are) not very readable?

I think people are trying to push an optional convenience feature way 
too far. I kind of wish comprehensions had been limited to one for 
clause (the source) and an optional if clause (the filter), as they 
pretty much are in math. Of course, I am one who switched to Python 
instead of lisp, perl, etc, *because* it read like pseudocode, with a 
nice mixture of expressions within statements, each in their own 
(logical) line. (I could have written this paragraph as a single 
sentence with a string of clauses, as I have seen in both older English 
and German, but I am not a fan of  that either ;-).

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list