摘要: import redef multiple_replace(text,adict): rx=re.compile('|'.join(map(re.escape,adict))) def one_xlat(match): return adict[match.group(0)] return rx.sub(one_xlat,text)print multiple_replace('abc123erts',{'a':'A','b':'B'})基本原理是 我们把要替换的字符串作为某个字典的key,对应的要 阅读全文
posted @ 2011-08-09 10:19 淘小杰 阅读(1763) 评论(0) 推荐(0) 编辑