- def populate_ranks(votes, ranks):
- names = list(votes.keys())
- names.sort(key=votes.get, reverse=True)
- for i, name in enumerate(names, 1):
- ranks[name] = i
- def get_winner(ranks):
- return next(iter(ranks))
- if __name__ == '__main__':
- ranks = {}
- votes = {
- 'other': 1281,
- 'polar bear': 587,
- 'fox': 863,
- }
- populate_ranks(votes, ranks)
- print(ranks)
- winner = get_winner(ranks)
- print(winner)
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |