Python - sum values in dictionary

dictionary, list, python

Solution

sum(item['gold'] for item in myList)

Problem

I have got pretty simple list: ``` example_list = [ {'points': 400, 'gold': 2480}, {'points': 100, 'gold': 610}, {'points': 100, 'gold': 620}, {'points': 100, 'gold': 620} ] ``` How can I sum all gold values? I'm looking for nice oneliner. Now I'm using this code (but it's not the best solution): ``` total_gold = 0 for item in example_list: total_gold += example_list["gold"] ```

Original source

Related problems