I have a list and a dictionary and I want to replace the list item with the value of the dictionary. A simplified version of my problem is as follows:
#This is a list
a=['dog', 'cat', 'cow']
#This is a dictionary
b={'dog': 'barks', 'cat': 'meows', 'cow': 'moos' }
Now list a[0] i.e dog is searched in the dictionary b and key dog will be found and I want its value barks in place of dog in the list a.
Expected output should be something like this
a=['barks','meows','moos']
I have been able to do this with the help of three text files in which one text file had the format 'key-value' and in other two I extracted key and values respectively with the help of split() function and then later matching the index position to get the desired result. But, the problem is that the code is way too long. I tried to do the above approach which I asked but couldn't get to replace the values.