s = 'ab;cd|efg|hi,jkl|mn\topq;rst,uvw\txyz' def my_split(s, seps): res = [s] for sep in seps: t = [] list(map(lambda ss: t.extend(ss.split(sep)), res)) res = t return res #reduce + split from functools import reduce my_split2 = lambda s, seps: reduce(lambda l, sep: sum(map(lambda ss: ss.split(sep), l), []), seps, [s]) my_split2(s, ',;|\t')
執行結果:python
['ab', 'cd', 'efg', 'hi', 'jkl', 'mn', 'opq', 'rst', 'uvw', 'xyz']
s = 'ab;cd|efg|hi,jkl|mn\topq;rst,uvw\txyz' import re re.split('[;,|\t]+', s)
執行結果:正則表達式
['ab', 'cd', 'efg', 'hi', 'jkl', 'mn', 'opq', 'rst', 'uvw', 'xyz']