I have dictionary with Word and its closest related words.
I want to replace the related words in the string with original word. Currently I am able replace words in th
I think you can replace by new dict with regex
from this answer:
d = {'Indian': 'India, Ind, ind.',
'Restaurant': 'Hotel, Restrant, Hotpot',
'Pub': 'Bar, Baar, Beer',
'1888': '188, 188., 18'}
d1 = {r'(?
EDIT (Function for the above code):
def replace_words(d, col):
d1={r'(?
EDIT1:
If get errors like:
regex error- missing ), unterminated subpattern at position 7
is necessary escape regex values in keys:
import re
def replace_words(d, col):
d1={r'(?