Help with splitting
Brian Beck
exogen at gmail.com
Fri Apr 1 18:01:49 EST 2005
RickMuller wrote:
> There's a chance I was instead thinking of something in the re module,
> but I also spent some time there without luck. Could someone point me
> to the right function, if it exists?
The re solution Jeremy Bowers is what you want. Here's another (probably
much slower) way for fun (with no surrounding empty strings):
py> from itertools import groupby
py> [''.join(g) for k, g in groupby(' test ing ', lambda x: x.isspace())]
[' ', 'test', ' ', 'ing', ' ']
I tried replacing the lambda thing with an attrgetter, but apparently my
understanding of that isn't perfect... it groups by the identify of the
bound method instead of calling it...
--
Brian Beck
Adventurer of the First Order
More information about the Python-list
mailing list