from functools import reduce
def replace_char(s, oldChar, newChar ):
return reduce(lambda s, char: s.replace(char, newChar), oldChar, s)
s = 'aaa,bbb/ccc|ddd\tzzz?ooo'
new_s = replace_char(s, ',/|\t?', ' ')
print(new_s)
===================================
aaa bbb ccc ddd zzz ooo
【python】字符串中多个字符替换为1个字符
最新推荐文章于 2024-07-20 02:34:09 发布