title: How to find common keys in a list of dicts and sort them by value?
body: <p>I want to create a finalDic which contains common keys and sum of their values   </p>
  
  <pre><code>myDic = [{2:1, 3:1, 5:2}, {3:4, 6:4, 2:3}, {2:5, 3:6}, ...]
  </code></pre>
  
  <p>First find common keys</p>
  
  <pre><code>commonkey = [{2:1, 3:1}, {2:3, 3:4}, {2:5, 3:6}]
  </code></pre>
  
  <p>Then Sum and sort by their values</p>
  
  <pre><code>finalDic= {3:11, 2,9}
  </code></pre>
  
  <p>I've tried this and not even close what i want</p>
  
  <pre><code>import collections
  
  myDic = [{2:1, 3:1, 5:2}, {3:4, 6:4, 2:3}, {2:5, 3:6}]
  
  def commonKey(x):
      i=0
      allKeys = []
      while i&lt;len(x):
          for key in x[0].keys():
              allKeys.append(key)
          i=i+1
      commonKeys = collections.Counter(allKeys)
      commonKeys = [i for i in commonKeys if commonKeys[i]&gt;len(x)-1]
      return commonKeys
  
  print commonKey(myDic)
  </code></pre>
  
  <p>Thanks</p>