From 79a96fa5a5b3562f335a77dbc4e455fd114baf30 Mon Sep 17 00:00:00 2001 From: DaniaK123 <152022387+DaniaK123@users.noreply.github.com> Date: Sat, 14 Dec 2024 17:41:22 +0000 Subject: [PATCH 1/2] Update main.py --- app/main.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..3b250e22e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,23 @@ class Person: - # write your code here - pass + people = {} + 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: - # write your code here - pass + +def create_person_list(people: list) -> None: + person_list = [] + for person in people: + person_instance = Person(name=person["name"], age=person["age"]) + person_list.append(person_instance) + + for person in people: + person_instance = Person.people[person["name"]] + if "wife" in person and person["wife"] is not None: + person_instance.wife = Person.people[person["wife"]] + elif "husband" in person and person["husband"] is not None: + person_instance.husband = Person.people[person["husband"]] + + return person_list From 2a3d93166a1f816c0808c7f62f4c3b941de680c7 Mon Sep 17 00:00:00 2001 From: DaniaK123 <152022387+DaniaK123@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:21:45 +0000 Subject: [PATCH 2/2] Update main.py --- app/main.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/main.py b/app/main.py index 3b250e22e..a17740f87 100644 --- a/app/main.py +++ b/app/main.py @@ -4,20 +4,18 @@ class Person: def __init__(self, name: str, age: int) -> None: self.name = name self.age = age - Person.people[name] = self + self.people[name] = self -def create_person_list(people: list) -> None: - person_list = [] - for person in people: - person_instance = Person(name=person["name"], age=person["age"]) - person_list.append(person_instance) +def create_person_list(people: list) -> list: + for human in people: + Person(human["name"], human["age"]) - for person in people: - person_instance = Person.people[person["name"]] - if "wife" in person and person["wife"] is not None: - person_instance.wife = Person.people[person["wife"]] - elif "husband" in person and person["husband"] is not None: - person_instance.husband = Person.people[person["husband"]] + for human in people: + if human.get("wife"): + Person.people[human["name"]].wife = Person.people[human["wife"]] + if human.get("husband"): + Person.people[human["name"]].husband \ + = Person.people[human["husband"]] - return person_list + return list(Person.people.values())