Skip to content

Instantly share code, notes, and snippets.

@johnpaulhayes
Created February 14, 2017 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpaulhayes/574d9e6eff43a097055dd638a7e40196 to your computer and use it in GitHub Desktop.
Save johnpaulhayes/574d9e6eff43a097055dd638a7e40196 to your computer and use it in GitHub Desktop.
Sum an items value in a list of dictionaries
from collections import defaultdict
table = [{"name": "a", "value": 10}, {"name": "b", "value": 110}, {"name": "b", "value": 10}]
c = defaultdict(int)
for d in table:
c[d['name']] += d['value']
print c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment