0

How to sum of inner values of a each key in dictionary

d={ "BMW":{"black":5, "white":2}, "Benz":{"black":2, "blue":1}} how to sum of cars and output be: BMW: 7 Benz: 3

23rd Feb 2017, 11:40 AM
hamid
hamid - avatar
2 Réponses
+ 3
Something like this: for k,v in d.items(): print k + ': ' + str(sum(v.values()))
23rd Feb 2017, 11:52 AM
Jehad Al-Ansari
Jehad Al-Ansari - avatar
0
thank you
24th Feb 2017, 1:31 PM
hamid
hamid - avatar