[Python-ideas] More power in list comprehensions with the 'as' keyword
Mathias Panzenböck
grosser.meister.morti at gmx.net
Thu Aug 28 18:20:05 CEST 2008
Marcin 'Qrczak' Kowalczyk schrieb:
> 2008/8/28 Cesare Di Mauro <cesare.dimauro at a-tono.com>:
>
>> A solution could be this:
>>
>> [stripped for l in text.split('\n') with l.strip() as stripped if stripped != '']
>>
>> so that you can keep both values (l and l.strip()) too.
>
> In Haskell this would be (I translate only the list comprehension
> structure, leaving expressions in Python syntax):
>
> [stripped | l <- text.split('\n'), let stripped = l.strip(), stripped != '']
>
> Python borrowed 2 out of 3 kinds of list comprehension constructs.
>
so maybe?
[stripped for l in text.split('\n') if stripped != '' let stripped = l.strip()]
but this would introduce a new keyword.
More information about the Python-ideas
mailing list