Skip to content
Advertisement

Performing mathematical operations on values from two dictionaries with same keys in Python

I have two dictionaries named as, lets say, a = {'A':{2021:45.65},'B':{2021:56.34}} and b = {'A':{2021:78.67},'B':{2021:87.54}}

I want to get the values from both A and B ‘sub-dictionaries’ and compute what percentage of value from the second dictionary is the value from the first dictionary.

I can’t seem to figure out a way how to access both the float values from different dictionaries and compute the result.

————————–UPDATE————————

Apologies about not comprehending my problem in a proper manner. I figured out a way to do that and if you think it has an issue still please do mention.

JavaScript

Advertisement

Answer

As has been mentioned in some of the comments breaking this into logical parts/steps can help a lot.

JavaScript

Proper code for anyone Googling their way here:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement