From c1ddde082e484c829be2a6839ed67f65579b4a67 Mon Sep 17 00:00:00 2001 From: nagafochfv Date: Wed, 11 Dec 2024 11:59:26 +0200 Subject: [PATCH] 'Solution2' --- app/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 845f5286..f263e99a 100644 --- a/app/main.py +++ b/app/main.py @@ -15,7 +15,15 @@ def create_person_list(peoples: list) -> list: for pers in peoples: person = Person.people[pers["name"]] if "wife" in pers and pers["wife"] is not None: - setattr(person, "wife", Person.people.get(pers["wife"])) + wife = Person.people.get(pers["wife"]) + if wife: + setattr(person, "wife", wife) + else: + setattr(person, "wife", None) if "husband" in pers and pers["husband"] is not None: - setattr(person, "husband", Person.people.get(pers["husband"])) + husband = Person.people.get(pers["husband"]) + if husband: + setattr(person, "husband", husband) + else: + setattr(person, "husband", None) return person_list