title: Sum the nested dictionary values in python
body: <p>I have a dictionary like this,</p>
  
  <pre><code>data={11L: [{'a': 2, 'b': 1},{'a': 2, 'b': 3}],
  22L: [{'a': 3, 'b': 2},{'a': 2, 'b': 5},{'a': 4, 'b': 2},{'a': 1, 'b': 5}, {'a': 1, 'b': 0}],
  33L: [{'a': 1, 'b': 2},{'a': 3, 'b': 5},{'a': 5, 'b': 2},{'a': 1, 'b': 3}, {'a': 1, 'b': 6},{'a':2,'b':0}],
  44L: [{'a': 4, 'b': 2},{'a': 4, 'b': 5},{'a': 3, 'b': 1},{'a': 3, 'b': 3}, {'a': 2, 'b': 3},{'a':1,'b':2},{'a': 1, 'b': 0}]}
  </code></pre>
  
  <p>Here i ll get rid of the outer keys, and give new key values 1, 2 , 3 so on, i want to get the result as shown below,</p>
  
  <pre><code>result={1:{'a':10,'b':7},2:{'a':11,'b':18},3:{'a':12,'b':5},4:{'a':5,'b':11},5:{'a':3,'b':9},6:{'a':3,'b':2},7:{'a':1,'b':0}}
  </code></pre>
  
  <p>I tried some thing like this, but i dint get the required result, </p>
  
  <pre><code>d = defaultdict(int)
  for dct in data.values():
    for k,v in dct.items():
      d[k] += v
  print dict(d)
  </code></pre>
  
  <p>I want the keys of result dictionary to be dynamic, like in the above data dictionary we have 44 which has highest with 7 key value pairs, hence we have the result dictionary with 7 keys and so on</p>