[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 regexps are likely the right way to do this kind of tokenization. The string split() method doesn't return the split value so that is less than helpful for your application: 'a=b'.split() --> ['a', 'b'] The new str.partition() method will return the split value and is suitable for successive applications: 'a:=b+c'.partition(':=') --> ('a', ':=', 'b+c') FWIW, when someone actually does want something that behaves like str.split() but with multiple split values, one approach is to replace each of the possible splitters with a single splitter: def multi_split(s, splitters): first = splitters[0] for splitter in splitters: s = s.replace(splitter, first) return s.split(first) print multi_split( 'a:=b+c' , [':=','+'] ) Raymond -- http://mail.python.org/mailman/listinfo/python-list