Help with dictionaries - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with dictionaries (/thread-26892.html) |
Help with dictionaries - bwdu - May-17-2020 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]} RE: Help with dictionaries - deanhystad - May-17-2020 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) |