I have two dictionaries as:
d={'doc_1': {'hope': 1, 'court': 2}, 'doc_2': {'hope': 1, 'court': 1}, 'doc_3': {'hope': 1, 'mention': 1}}
and
count={'doc_1': 6, 'doc_2': 5, 'doc_3': 12}
All I want to divide the values of nested dictionary of dictionary d
with values of dictionary count
based on same keys of both dictionaries.
Expected output:-
new={{'doc_1': {'hope': 0.16666666, 'court': 0.3333333}, 'doc_2': {'hope': 0.2, 'court': 0.2}, 'doc_3': {'hope': 0.0833333, 'mention': 0.0833333}}
.
What I did so far:
new={}
for k,v in d.items():
for p,q in count.items():
for w,r in v.items():
if k==p:
ratio=r/q
new[k][w]=ratio
That gave me an error!!!