title: Group by multiple keys and summarize/average values of a list of dictionaries
body: <p>What is the most pythonic way to group by multiple keys and summarize/average values of a list of dictionaries in Python please? Say I have a list of dictionaries as below:</p>
  
  <pre><code>input = [
  {'dept': '001', 'sku': 'foo', 'transId': 'uniqueId1', 'qty': 100},
  {'dept': '001', 'sku': 'bar', 'transId': 'uniqueId2', 'qty': 200},
  {'dept': '001', 'sku': 'foo', 'transId': 'uniqueId3', 'qty': 300},
  {'dept': '002', 'sku': 'baz', 'transId': 'uniqueId4', 'qty': 400},
  {'dept': '002', 'sku': 'baz', 'transId': 'uniqueId5', 'qty': 500},
  {'dept': '002', 'sku': 'qux', 'transId': 'uniqueId6', 'qty': 600},
  {'dept': '003', 'sku': 'foo', 'transId': 'uniqueId7', 'qty': 700}
  ]
  </code></pre>
  
  <p>Desired output for aggregation:</p>
  
  <pre><code>output=[
  {'dept': '001', 'sku': 'foo', 'qty': 400},
  {'dept': '001', 'sku': 'bar', 'qty': 200},
  {'dept': '002', 'sku': 'baz', 'qty': 900},
  {'dept': '002', 'sku': 'qux', 'qty': 600},
  {'dept': '003', 'sku': 'foo', 'qty': 700}
  ]
  </code></pre>
  
  <p>or average:</p>
  
  <pre><code>output=[
  {'dept': '001', 'sku': 'foo', 'avg': 200},
  {'dept': '001', 'sku': 'bar', 'avg': 200},
  {'dept': '002', 'sku': 'baz', 'avg': 450},
  {'dept': '002', 'sku': 'qux', 'avg': 600},
  {'dept': '003', 'sku': 'foo', 'avg': 700}
  ]
  </code></pre>
  
  <p>I have found this: <a href="https://stackoverflow.com/questions/18066269/group-by-and-aggregate-the-values-of-a-list-of-dictionaries-in-python">Group by and aggregate the values of a list of dictionaries in Python</a> but it doesn't seem to give me what I want.</p>