Python Forum

Full Version: Help with dictionaries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone! I have looked for a way to sum up the elements of each value which are lists but couldn't find a solution. I'm curious about if there is a way to reach the elements in the value lists. Can you help me with that?

b = {"a":[0,5,3,-5], "b":[5,5,5,0], "c":[1,5,5,0]}
Actually this is what I am trying to get as output:

b = {"a":[3],"b":[15],"c":[11]}
b = {"a":[0,5,3,-5], "b":[5,5,5,0], "c":[1,5,5,0]}
sums = {key: sum(value) for key, value in b.items()}
print(sums)