Python Forum
an array to count votes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an array to count votes
#3
Pointing to: https://docs.python.org/3/library/collec...ns.Counter

Simple demonstration:
from collections import Counter

# using a Counter to count unique objects like str or int
# you can also add or substract Counter-objects.
result = Counter(["Trump", "Trump", "Trump", "Biden"]) + Counter(["Trump"] * 10)

print(result)
Output:
Counter({'Trump': 13, 'Biden': 1})
But it's your task to write the program.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
an array to count votes - by thechungusmaximus - Mar-09-2022, 01:56 AM
RE: an array to count votes - by Yoriz - Mar-09-2022, 06:30 AM
RE: an array to count votes - by DeaD_EyE - Mar-09-2022, 03:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Count Letters in a Sentence (without using the Count Function) bhill 3 5,247 Jun-19-2018, 02:52 AM
Last Post: bhill

Forum Jump:

User Panel Messages

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