[Python-ideas] More power in list comprehensions with the 'as' keyword
Ron Adam
rrr at ronadam.com
Thu Aug 28 18:14:30 CEST 2008
Josiah Carlson wrote:
> -1 on the feature, I use the compound expression as below, only have
> the internal item be a generator expression to reduce peak memory
> usage. Also, the != condition is unnecessary.
>
> [t for t in (t.strip() for t in text.split('\n')) if t]
If split was a bit smarter...
text.split(pattern=(' *\n+ *'))
;-)
It can be done with the re module, but I need to look that up each time I
use it since I don't use it enough to remember all it's subtleties.
Ron
More information about the Python-ideas
mailing list