Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count of sums
#1
I would like to count sum(subsets) in the following code, how can i do this? thanks.

import itertools

thelist = [0, 0, 0, 1, 1, 2, 2, 1]
for L in range(5,6):
    for subset in itertools.combinations(thelist, L):
        print(f"{subset} => {sum(subset)}") 
For example, I would like to count where sum(subset)=6,7 etc.
Reply


Messages In This Thread
Count of sums - by mattis - Oct-22-2018, 07:55 PM
RE: Count of sums - by Larz60+ - Oct-22-2018, 08:14 PM
RE: Count of sums - by mattis - Oct-22-2018, 08:21 PM
RE: Count of sums - by nilamo - Oct-22-2018, 08:26 PM
RE: Count of sums - by mattis - Oct-22-2018, 08:36 PM
RE: Count of sums - by nilamo - Oct-22-2018, 08:40 PM
RE: Count of sums - by mattis - Oct-22-2018, 08:44 PM
RE: Count of sums - by Larz60+ - Oct-22-2018, 08:49 PM
RE: Count of sums - by Larz60+ - Oct-22-2018, 08:50 PM
RE: Count of sums - by mattis - Oct-22-2018, 08:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Row Count and coloumn count Yegor123 4 1,348 Oct-18-2022, 03:52 AM
Last Post: Yegor123

Forum Jump:

User Panel Messages

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