2021年3月31日星期三

Python functions for nested dictionary

Given a dictionary :

dic = {      2: {'p': 0.225, 'i': 0.159, 'e': 0.116, 'c': 0.098, 'a': 0.09311},      7: {'r': 0.186, 's': 0.148, 'd': 0.145, 'a': 0.005},      8: {'r': 0.1, 's': 0.2}  

I want the output as a dictionary with key as 'a', 'p', ... and their values as the addition of their values in a nested dictionary

Expected output:

{'p': 0.025 , 'a' 0.09811 ....}  
https://stackoverflow.com/questions/66897880/python-functions-for-nested-dictionary April 01, 2021 at 11:02AM

没有评论:

发表评论