fork download
  1.  
  2. import re
  3.  
  4.  
  5. translation = {
  6. r'\{fuck\}': '{1}',
  7. 'you': '{2}'
  8. }
  9.  
  10. text ='{fuck} you'
  11. pattern = re.compile(r'\b(' + '|'.join(translation.keys()) + r')\b')
  12. print(r'\b(' + '|'.join(translation.keys()) + r')\b')
  13. print(pattern.sub(lambda x: translation[x.group()], text))
  14.  
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
\b(you|\{fuck\})\b
{fuck} {2}