def asr_to_correct(text): rep = dict((re.escape(k), v) for k, v in error_asr_map.items()) pattern = re.compile("|".join(rep.keys())) text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text) return text