how do I sum up this python Dictionary and get the average?
Question: d =[{'C': 0, 'B': 2.0, 'A': 7.0, 'D': 3.0}, {'C': 2.0, 'B': 0, 'A': 5.0, 'D':
5.0}, {'C': 7.0, 'B': 5.0, 'A': 0, 'D': 10.0}, {'C': 3.0, 'B': 5.0, 'A': 10.0,
'D': 0}]

how do I sum up this python Dictionary and get the average ?...


Answer: 
    >>> from functools import reduce
    >>> d
    [{'D': 3.0, 'A': 7.0, 'C': 0, 'B': 2.0}, {'D': 5.0, 'A': 5.0, 'C': 2.0, 'B': 0}, {'D': 10.0, 'A': 0, 'C': 7.0, 'B': 5.0}, {'D': 0, 'A': 10.0, 'C': 3.0, 'B': 5.0}]
    >>> l = len(d)
    >>> s = reduce(lambda x,y: {z:x[z]+y[z] for z in ['A','B','C','D']}, d)
    >>> s = {x:s[x]/l for x in s}
    >>> s
    {'D': 4.5, 'A': 5.5, 'C': 3.0, 'B': 3.0}
    >>>
    

