I have a dictionary that looks like:
d = {'alleged': ['truths', 'fiels', 'fact', 'infidelity', 'incident'],
'greased': ['axle', 'wheel', 'wheels', 'fields', 'enGine', 'pizza'],
'plowed': ['fields', 'field', 'field', 'incident', '', '']}
I would like to go over it and replace some items for another strings. The strings to be find and the ones to replace them are also in a dictionary, in which the key is the string to be found and the value is the string to replace it:
d_find_and_replace = {'wheels':'wheel', 'Field': 'field', 'animals':'plants'}
I tried to use a function like:
def replace_all(dic1, dic2):
for i, j in dic.items():
dic3 = dic1.replace(i, j)
return(dic3)
but it won't work because obviously, it uses replace built-in function replace inside it, and it is not possible to use it for dictionaries. Any suggestions on how to do this? Thank you very much for any help.
Edited to correct spelling mistakes.
d_find_and_replacedict is a bit of a mess. Check that your quotes are in the right places.ddictionary also has several errors (no opening quote onalleged, close bracket inside thegreasedlist). Clean those up so it works first then you can debug the replacement.