
Aug. 28, 2008
4:14 p.m.
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