拆分字符串
1.
def my_split(s, ds):
l = [s]
for d in ds:
res = []
list(map(lambda x: res.extend(x.split(d)), l))
l = res
return l
s = 'abc;dwwewfe;rqger|gert;klg jotrg pa|s;dooo'
ds = '; |'
l = my_split(s, ds)
print(l)
output:
['abc', 'dwwewfe', 'rqger', 'gert', 'klg', 'jotrg', 'pa', 's', 'dooo']
2.
import re
re.split(r'[; |]+', s) # + 代表至少一个 可以是多个
output:
['abc', 'dwwewfe', 'rqger', 'gert', 'klg', 'jotrg', 'pa', 's', 'dooo']