MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / populate_ranks

Function populate_ranks

example_code/item_025_example_17.py:24–28  ·  view source on GitHub ↗
(votes: Dict[str, int], ranks: Dict[str, int])

Source from the content-addressed store, hash-verified

22from typing import Dict, MutableMapping
23
24def populate_ranks(votes: Dict[str, int], ranks: Dict[str, int]) -> None:
25 names = list(votes.keys())
26 names.sort(key=votes.__getitem__, reverse=True)
27 for i, name in enumerate(names, 1):
28 ranks[name] = i
29
30def get_winner(ranks: Dict[str, int]) -> str:
31 return next(iter(ranks))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected