[Python-ideas] Map-then-filter in comprehensions

Terry Reedy tjreedy at udel.edu
Tue Mar 8 20:55:01 EST 2016


On 3/8/2016 9:17 AM, Allan Clark wrote:
> tl;dr What is support like for adding an 'as' clause to comprehension
> syntax? In order to allow map-then-filter, it might look like something
> this:
>
>      [y for x in numbers if abs(x) as y > 5]

-1

Comprehensions abbreviate a particular pattern of collection 
initialization, nested for and if statements, and collection 
augmentation innermost, with the only binding being the loop names. 
They are easily translated back to the original pattern, although move 
than one level of nesting can challenge comprehension in the normal 
meaning of the work.  I strongly feel that the current correspondence 
between conprehensions and statements should be maintained.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list