[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']

좋은 웹페이지 즐겨찾기