Created
February 2, 2015 13:29
-
-
Save kxxoling/42c1944ae911e845a7a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def replace_words(text, word_dic): | |
yo = re.compile('|'.join(map(re.escape, word_dic))) | |
def translate(mat): | |
return word_dic[mat.group(0)] | |
return yo.sub(translate, text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment