python .replace multiple

import re

rep = {"condition1": "", "condition2": "text"} # define desired replacements here

# use these three lines to do the replacement
rep = dict((re.escape(k), v) for k, v in rep.iteritems()) 
#Python 3 renamed dict.iteritems to dict.items so use rep.items() for latest versions
pattern = re.compile("|".join(rep.keys()))
text = pattern.sub(lambda m: rep[re.escape(], text)

Here is what the above code is Doing:
1. re.escape() escapes all the non-alphanumeric characters in the keys of the dictionary.
2. The keys are joined together with the | character, which acts as an OR operator.
3. The pattern is compiled into a regular expression object.
4. The text is passed to the sub() method of the regular expression object.
5. The lambda function is called for every match, and the matched text is passed as an argument.
6. The matched text is looked up in the dictionary, and the corresponding value is returned.
7. The value is substituted for the matched text in the new string.