Python Forum
combining lists in a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
combining lists in a dictionary
#5
just straightly pass the dict to sum function. 2nd arguments is just optional to add the result. hope this will help.

>>> dict = {'a':[1,2,3,4,5], 'b':[5,10,15,20]}
>>> sum(dict['a'])
15
>>> sum(dict['a'], 5)
20
>>> sum(dict['b'])
50
>>> sum(dict['b'], 50)
100
>>> 
Reply


Messages In This Thread
combining lists in a dictionary - by Skaperen - Nov-03-2019, 12:18 AM
RE: combining lists in a dictionary - by ichabod801 - Nov-03-2019, 03:04 AM
RE: combining lists in a dictionary - by Skaperen - Nov-03-2019, 11:34 PM
RE: combining lists in a dictionary - by ichabod801 - Nov-03-2019, 11:45 PM
RE: combining lists in a dictionary - by MckJohan - Nov-03-2019, 11:53 PM
RE: combining lists in a dictionary - by Skaperen - Nov-04-2019, 12:45 AM
RE: combining lists in a dictionary - by perfringo - Nov-04-2019, 06:18 AM
RE: combining lists in a dictionary - by ichabod801 - Nov-04-2019, 03:02 PM
RE: combining lists in a dictionary - by perfringo - Nov-04-2019, 03:13 PM
RE: combining lists in a dictionary - by DeaD_EyE - Nov-04-2019, 05:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 2,159 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  combining lists stealth 3 2,393 Feb-08-2022, 04:36 AM
Last Post: deanhystad
  Split dict of lists into smaller dicts of lists. pcs3rd 3 3,273 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Help: for loop with dictionary and nested lists mart79 1 2,371 Apr-12-2020, 02:52 PM
Last Post: TomToad
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 4,969 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020