Skip to content

Instantly share code, notes, and snippets.

@drammock
Created May 27, 2020 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drammock/0c75f3f7c389234004e7b62a22c1a230 to your computer and use it in GitHub Desktop.
Save drammock/0c75f3f7c389234004e7b62a22c1a230 to your computer and use it in GitHub Desktop.
from pyrankvote import Ballot, Candidate, instant_runoff_voting
votes = dict(tri=(10, 8, 2, 3, 4),
kaj=(1, 9, 10),
dan=(2, 10, 4, 5),
gus=(5, 3, 7),
mer=(5, 1, 4),
ori=(6, 2, 10, 4),
jai=(4, 1, 10, 5),
ch_=(4, 7, 10, 9)
)
candidates = [Candidate(n) for n in range(1, 11)] # change for actual num. of candidates
ballots = list()
for choices in votes.values():
ballots.append(Ballot(ranked_candidates=[Candidate(n) for n in choices]))
election_result = instant_runoff_voting(candidates, ballots)
print(election_result.get_winners())
# to see details of the last round (or other rounds, change the -1 index):
election_result.rounds[-1].candidate_results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment