From e3dd8fe2e1a39b6df1bf0632c4efdb24fab2362c Mon Sep 17 00:00:00 2001 From: DvRodri8 Date: Wed, 13 Dec 2023 17:17:01 +0100 Subject: [PATCH] refactor: pairing algorithm --- secretsanta/domain.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/secretsanta/domain.py b/secretsanta/domain.py index 458adbc..e3d958a 100644 --- a/secretsanta/domain.py +++ b/secretsanta/domain.py @@ -15,20 +15,10 @@ class Group(BaseModel): @staticmethod def pair(names: list[str]) -> dict[str, str]: - names_copy = names[:] - random.shuffle(names_copy) - - pairings = {} - for i, name in enumerate(names): - pair = names_copy[i] - while pair == name: - random.shuffle(names_copy) - pair = names_copy[i] - - pairings[name] = pair - - return pairings - + random.shuffle(names) + names_copy = names[1:] + names_copy.append(names[0]) + return dict(zip(names, names_copy)) class IRepo(ABC): @abstractmethod