【python】多个字符分割字符串

from itertools import chain
from functools import reduce

def split_str(s, char):
    return reduce(lambda s, c: chain(*map(lambda _: _.split(c), s)), char, [s])

s = 'aaa,bbb|ccc\tddd'
l = split_str(s, ',|\t')
print(l)
print(list(l))

==================================================
0x0000000001E816D8>
['aaa', 'bbb', 'ccc', 'ddd']

你可能感兴趣的:(【python】多个字符分割字符串)