multi split function taking delimiter list
Kent Johnson
kent at kentsjohnson.com
Tue Nov 14 15:19:18 EST 2006
martinskou at gmail.com 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?
What do you have against regexp? re.split() does exactly what you want:
In [1]: import re
In [2]: re.split(r'(:=|\+)', 'a:=b+c')
Out[2]: ['a', ':=', 'b', '+', 'c']
Kent
More information about the Python-list
mailing list