Skip to content

Commit d08f55b

Browse files
committed
Sort candidate keys in each round by descending order of topranks
1 parent 9fd9427 commit d08f55b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

abiflib/irv_tally.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,16 @@ def IRV_dict_from_jabmod(jabmod):
311311
canddict = retval['canddict'] = jabmod['candidates']
312312
candlist = list(jabmod['candidates'].keys())
313313
votelines = jabmod['votelines']
314+
314315
(retval['winner'], retval['rounds'], retval['roundmeta']) = \
315316
_irv_count_internal(candlist, votelines, roundnum=1)
316317

318+
# Sort candidate keys in each round by descending order of topranks
319+
if retval['rounds']:
320+
for idx, round_dict in enumerate(retval['rounds']):
321+
sorted_items = sorted(round_dict.items(), key=lambda item: item[1], reverse=True)
322+
retval['rounds'][idx] = {k: v for k, v in sorted_items}
323+
317324
winner = retval['winner']
318325
if len(winner) > 1:
319326
winnerstr = " and ".join(canddict[w] for w in sorted(winner))

0 commit comments

Comments
 (0)