def make_xlat(*args, **kwds):
adict = dict(*args, **kwds)<EOL>rx = re.compile("<STR_LIT:|>".join(map(re.escape, adict)))<EOL>def one_xlat(match):<EOL><INDENT>return adict[match.group(<NUM_LIT:0>)]<EOL><DEDENT>def xlat(text):<EOL><INDENT>return rx.sub(one_xlat, text)<EOL><DEDENT>return xlat<EOL>
Replaces multiple patterns in a single pass.
From "Python Cookbook", O'Reilly, pg39

USAGE:
translate     = make_xlat(adict)
translate(text)