def replace_patterns(x, replace):
 for (from_, to) in iteritems(replace):
  x = x.replace(str(from_), str(to))
 return x

def replace_patterns ( x , replace ) : for ( from_ , to ) in iteritems ( replace ) : x = x . replace ( str ( from_ ) , str ( to ) ) return x
replace replace in string x .