Created
February 14, 2017 11:32
-
-
Save johnpaulhayes/574d9e6eff43a097055dd638a7e40196 to your computer and use it in GitHub Desktop.
Sum an items value in a list of dictionaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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