From c3a2e94cabccc65e15ffb53b2a944d9e8c433ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 16:58:10 +0200 Subject: [PATCH] =?UTF-8?q?feature/vysledky:=20funkce=20pro=20=C5=99azen?= =?UTF-8?q?=C3=AD=20v=C3=BDsledku=20na=20z=C3=A1klad=C4=9B=20k=C3=B3du=20v?= =?UTF-8?q?=20check=5Fwin();=20k=C3=B3d=20v=20check=5Fwin()=20nahrazen=20f?= =?UTF-8?q?unkc=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index a21b9ee..c3ed018 100644 --- a/main.py +++ b/main.py @@ -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