423,851 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,851 IT Pros & Developers. It's quick & easy.

Sum operation on list if dictionary based on key.

P: 1
I have a list of dictonary
[
{'code': 'L02', 'name': 'CREW SUPERVISOR', 'qty': 1},
{'code': 'L03', 'name': 'DRIVER', 'qty': 1},
{'code': 'L04', 'name': 'LABOURER', 'qty': 5},
{'code': 'L02', 'name': 'CREW SUPERVISOR', 'qty': 1},
{'code': 'L03', 'name': 'DRIVER', 'qty': 1},
{'code': 'L04', 'name': 'LABOURER', 'qty': 5},
{'code': 'L02', 'name': 'CREW SUPERVISOR', 'qty': 1},
{'code': 'L03', 'name': 'DRIVER', 'qty': 1}
]

I need a result like [{'code': 'L02', 'name': 'CREW SUPERVISOR', 'qty': 3},{'code': 'L03', 'name': 'DRIVER', 'qty': 3},{'code': 'L04', 'name': 'LABOURER', 'qty': 10}]

How can I achieve this?
Jul 19 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.