Loop over the dictionary’s items and use replace()
over txt
for key, val in dict.items():
txt = txt.replace(key, val)
Note: it is not a good idea to use dict
as a variable name since it is a builtin type in python
1
solved Python: Replace different words in a string using matching array values