Quickies

[categories] [index] [all (527)] [latest]

Python
  1. import re
    
    def strTr( text, dic ):
        """ Replaces keys of dic with values of dic in text.
            2005-02 by Emanuel Rumpf """
        pat = "(%s)" % "|".join( map(re.escape, dic.keys())  )
        return re.sub( pat, lambda m:dic[m.group()], text )