[Python-ideas] More power in list comprehensions with the 'as' keyword

Blake Winton bwinton at latte.ca
Wed Aug 27 20:12:10 CEST 2008


George Sakkis wrote:
> 
> On Wed, Aug 27, 2008 at 12:51 PM, Tarek Ziadé <ziade.tarek at gmail.com 
> <mailto:ziade.tarek at gmail.com>> wrote:
>     The pattern can be generically resumed like this :
>        [transform(e) for e in seq if some_test(transform(e))]
>     So what about using the 'as' keyword to extend lists comprehensions, and
>     to avoid calling transform() twice ?
>      
>     Could be:
>        [transform(e) as transformed for e in seq if some_test(transformed)]
> 
> -1; not general enough to justify the extra overhead (both in human 
> mental effort and compiler changes), given that the current alternatives 
> (esp. genexps) are already quite readable and more flexible.

-1; It's not clear to me that transform(e) is what's going into the 
list.  And what if I want to test on two different values (or two 
different transforms on the same value), which one is put into the 
comprehension?

Later,
Blake.



More information about the Python-ideas mailing list