feature/vysledky: funkce pro řazení výsledku na základě kódu v check_win(); kód v check_win() nahrazen funkcí

This commit is contained in:
David Spáčil
2026-06-27 16:58:10 +02:00
parent 485f152a41
commit c3a2e94cab
+14 -7
View File
@@ -202,6 +202,17 @@ def add_players() -> None:
else:
break
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[str, int]], dict[str, int]]:
L: list[tuple[str, int]] = []
if s:
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
for k in d:
L.append((k, d[k]))
return L, d
def check_win() -> str:
over_limit: dict[str, int] = {}
for p in aggr:
@@ -211,17 +222,13 @@ def check_win() -> str:
winner: str = ""
if over_limit:
over_limit_sorted: dict[str, int] = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True))
over_limit_sorted_list: list[tuple[str, int]] = []
for ols in over_limit_sorted:
over_limit_sorted_list.append((ols, over_limit_sorted[ols]))
L, d = to_sorted_tuple(over_limit)
count: Counter = Counter(list(over_limit_sorted.values()))
count: Counter = Counter(list(d.values()))
for c in count:
if count[c] == 1:
winner = over_limit_sorted_list[0][0]
winner = L[0][0]
break
return winner