0
dictionary
hi i want to sum value of the dic that is list d = {"a": [1,2,2,3,6,] , "b":[8,5,6,1]} i want to sum for example 1 + 2 + 3 + 6 for key a
5 Antworten
+ 2
sum(d["a"])
+ 1
Make a `set` object from the `list` (dictionary value) to have unique values only, then sum the values in the `set`.
d = { "a" : [1, 2, 2, 3, 6,] , "b" : [8, 5, 6, 1] }
for key in d:
print(sum(set(d[key])))
0
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 no its unique
0
Thanks Seb TheS