I have to compare two dictonaries (unsorted). Threfore I would iterate over one dictonary and If key is in dictA and dictB, then do something with the values. (for example dictA[key] / dict[B])
The dicts looks like: total = {1951: 2, 1952: 2} years = {1922: 33, 1951: 1}
I would except that ratio would be {1951 : 0.5} but instead it is empty.
I have tried various methods. The last one:
for i in total:
if i in years:
ratio[i] = years[i] / total[i]
I have also tried to use
year.viewkeys() | total.viewkeys()
But it would just return me the keys, I need to process the values. (Or at least I dont know how atm)
You can find which keys are in both dictionaries using set intersection
Then use a dict comprehension to calculate the ratios