The following code returns the ratios as a dictionary with A
's keys. If this is not the desired behavior, please clarify.
The solution using dictionary comprehension:
a = {'A':1, 'B':5, 'D':6}
b = {'X':4, 'Y':8, 'Z':4}
{key:val_a/val_b for ((key, val_a), val_b) in zip(a.items(), b.values())}
# Output:
# {'A': 0.25, 'B': 0.625, 'D': 1.5}
If you want the ratios as an array without the keys, you can use list comprehension:
[val_a/val_b for (val_a, val_b) in zip(a.values(), b.values())]
# Output for example above
# [0.25, 0.625, 1.5]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…