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
4 Answers
+ 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