Handle ballots of uneven length
This commit is contained in:
parent
d1ffb55f08
commit
c45e514bfc
8
app.py
8
app.py
|
@ -354,11 +354,17 @@ def runoff(ballots):
|
|||
candidates = {}
|
||||
for ballot in ballots:
|
||||
for r in ballot:
|
||||
count[r.id] = [0] * len(ballot)
|
||||
if r.id not in count or len(count[r.id]) < len(ballot):
|
||||
log.debug("count[%d] <- %d elements", r.id, len(ballot))
|
||||
count[r.id] = [0] * len(ballot)
|
||||
candidates[r.id] = r
|
||||
for ballot in ballots:
|
||||
for pos, r in enumerate(ballot):
|
||||
log.debug("count = %s", count)
|
||||
log.debug("r.id = %s", r.id)
|
||||
log.debug("pos = %s", pos)
|
||||
count[r.id][pos] += 1
|
||||
log.debug("count[%d][%d]) = %d", r.id, pos, count[r.id][pos])
|
||||
result = sorted(count.keys(), key=lambda i: count[i])
|
||||
log.debug("result of this round:")
|
||||
for r in result:
|
||||
|
|
Loading…
Reference in New Issue