From 2c90946ed426a3222e87f485d0429846557b2e68 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 17 Dec 2024 18:40:20 +0200 Subject: [PATCH 1/2] Solution --- app/main.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..ca0905682 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,29 @@ class Person: - # write your code here - pass + people = {} -def create_person_list(people: list) -> list: - # write your code here - pass + def __init__(self, name: str, age: int) -> None: + self.name = name + self.age = age + Person.people[name] = self + + +def create_person_list(people_list: list) -> list: + + person_instances = [] + for person_data in people_list: + name = person_data.get("name") + age = person_data.get("age") + person = Person(name, age) + person_instances.append(person) + + for person_data in people_list: + name = person_data.get("name") + current_person = Person.people[name] + + if "wife" in person_data and person_data["wife"]: + current_person.wife = Person.people[person_data["wife"]] + if "husband" in person_data and person_data["husband"]: + current_person.husband = Person.people[person_data["husband"]] + + return person_instances From 0b44dca849a073301184aa80df93a4c615c66e38 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Dec 2024 15:26:24 +0200 Subject: [PATCH 2/2] Solution --- app/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/main.py b/app/main.py index ca0905682..a9e81a16e 100644 --- a/app/main.py +++ b/app/main.py @@ -5,6 +5,8 @@ class Person: def __init__(self, name: str, age: int) -> None: self.name = name self.age = age + self.wife = None + self.husband = None Person.people[name] = self @@ -23,7 +25,11 @@ def create_person_list(people_list: list) -> list: if "wife" in person_data and person_data["wife"]: current_person.wife = Person.people[person_data["wife"]] + else: + delattr(current_person, "wife") if "husband" in person_data and person_data["husband"]: current_person.husband = Person.people[person_data["husband"]] + else: + delattr(current_person, "husband") return person_instances