I am trying to replace a word in a string with multilple words and produce all the strings as an output.
For example 'disease' in 'lysosome storage disease' should be replaced by 'disease' , 'diseases', 'disorder', 'disorders','syndrome','syndromes' and produce following output.
lysosome storage disease
lysosome storage diseases
lysosome storage disorder
lysosome storage disorders
lysosome storage syndrome
lysosome storage syndromes
I am trying following lines of code but, in the end I am getting only the last string.
def multiple_replace(string, rep_dict):
pattern = re.compile("|".join([re.escape(k) for k in sorted(rep_dict,key=len,reverse=True)]), flags=re.DOTALL)
return pattern.sub(lambda x: rep_dict[x.group(0)], string)
multiple_replace("lysosome storage disease", {'disease':'disease', 'disease':'diseases', 'disease':'disorder', 'disease':'disorders','disease':'syndrome','disease':'syndromes'})