Sum values in a dict of lists

前端 未结 4 1169
名媛妹妹
名媛妹妹 2021-01-07 10:21

If I have a dictionary such as:

my_dict = {\"A\": [1, 2, 3], \"B\": [9, -4, 2], \"C\": [3, 99, 1]}

How do I create a new dictionary with su

4条回答
  •  生来不讨喜
    2021-01-07 10:55

    Try This:

    def sumDictionaryValues(d):
        new_d = {}
        for i in d:
            new_d[i]= sum(d[i])
        return new_d
    

提交回复
热议问题