[Python-ideas] str.split with multiple individual split characters
Stephen J. Turnbull
stephen at xemacs.org
Mon Feb 28 07:19:13 CET 2011
Carl M. Johnson writes:
> Anyway, you'll get no argument from me: Regexes are easy once you know
> regexes. For whatever reason though, I've never been able to
> successfully, permanently learn regexes.
How about learning them long enough to write
>>> def multisplit (source, char1, char2):
... return re.split("".join(["[",char1,char2,"]"]),source)
...
>>> multisplit ("a-b_c","_","-")
['a', 'b', 'c']
or a generalization as needed?
I'm not unsympathetic to the need, but there are just too many Zen or
near-Zen principles violated by this proposal. I'm getting old and
cranky enough myself that I have to explicitly remind myself to do
this kind of thing, but arguing against the Zen doesn't work very
well, even here on python-ideas. Life is easier for me when I
remember to help myself!
More information about the Python-ideas
mailing list