If I had a dictionary like the following (whole dictionary is omitted to make this readable):
{"'hood": '-0.375',
'-0.4': '',
'0': '-0.375',
'101': '-0.25',
'105': '-0.25',
'300': '-0.25',
'3tc': '-0.25',
'400': '-0.25',
'FALSE': '-0.486111111',
'TRUE': '0.259615385',
}
and a list like the following:
['This', 'is', 'a', 'media', 'player', 'that', 'is', 'FALSE', 'TRUE']
how could I go through the dictionary and check if a word from the list exists in the dictionary and if it does exist, add up its value associated with the word? My goal is to have a final number that represents the sum of the values from the dictionary when the key word from the list exists.
For example, in my list above the words 'FALSE' and 'TRUE' are in the list and since those two words are also present in the dictionary above, I would add their values of -0.486111111 and 0.259615385 together to create a single number as the final output.
I also realize that the values for the dictionary are strings so I would have to convert those to numbers to properly add them.
I have tried to loop through the list and check if it is present in the dictionary that way but I am having issues.