diff --git a/app.py b/app.py index c9b444d..b06dfd8 100644 --- a/app.py +++ b/app.py @@ -303,11 +303,11 @@ def runoff(ballots): candidates = {} for ballot in ballots: for r in ballot: - count[r.id] = 0 + count[r.id] = [0] * len(ballot) candidates[r.id] = r for ballot in ballots: - # The votes are sorted by position, so the first entry is the favourite - count[ballot[0].id] += 1 + for pos, r in enumerate(ballot): + count[r.id][pos] += 1 result = sorted(count.keys(), key=lambda i: count[i]) log.debug("result of this round:") for r in result: diff --git a/utils/instantrunoff b/utils/instantrunoff index a8a5428..a663c76 100755 --- a/utils/instantrunoff +++ b/utils/instantrunoff @@ -48,11 +48,11 @@ def runoff(ballots): candidates = {} for ballot in ballots: for r in ballot: - count[r.id] = 0 + count[r.id] = [0] * len(ballot) candidates[r.id] = r for ballot in ballots: - # The votes are sorted by position, so the first entry is the favourite - count[ballot[0].id] += 1 + for pos, r in enumerate(ballot): + count[r.id][pos] += 1 result = sorted(count.keys(), key=lambda i: count[i]) print("result of this round:") for r in result: