Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count of sums
#5
thank you, Nilamo.

I changed it like this with your suggestion. but I couldn't get the result. I am a new learner, what am I doing wrong here? please


import itertools
from collections import Counter

thelist = [0, 0, 0, 1, 1, 2]
for L in range(5,6):
    for subset in itertools.combinations(thelist, L):
        print(f"{subset} => {sum(subset)}")
totals = Counter()
totals[sum(subset)] += 1
totals
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,382 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