[EMAIL PROTECTED] wrote:

> Hi, I'm looking for something like:
> 
> multi_split( 'a:=b+c' , [':=','+'] )
> 
> returning:
> ['a', ':=', 'b', '+', 'c']
> 
> whats the python way to achieve this, preferably without regexp?

I think in this case the regexp approach is the simplest, though:

>>> def multi_split(text, splitters):
...     return re.split("(%s)" % "|".join(re.escape(splitter) for splitter
in splitters), text)
...
>>> multi_split("a:=b+c", [":=", "+"])
['a', ':=', 'b', '+', 'c']

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to