# coding:utf-8 import re def multiple_replace(text, adict): rx = re.compile('|'.join(map(re.escape, adict))) def one_xlat(match): return "%s" % adict[match.group(0)] return rx.sub(one_xlat, text)
来源于网络
# coding:utf-8 import re def multiple_replace(text, adict): rx = re.compile('|'.join(map(re.escape, adict))) def one_xlat(match): return "%s" % adict[match.group(0)] return rx.sub(one_xlat, text)
来源于网络