
The split/strip stuff is simple on purpose; it's fast. Tossing in regular expressions handling is a great way to slow down the general case, never mind if you actually want to split on the passed literal string. - Josiah On Thu, Aug 28, 2008 at 9:14 AM, Ron Adam <rrr@ronadam.com> wrote:
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