From 6fc07f3b815d275d3a9258d4816248fc2f16ed23 Mon Sep 17 00:00:00 2001 From: Oleksandr Asauliak Date: Mon, 18 Sep 2023 21:42:15 +0300 Subject: [PATCH 1/2] restart --- app/main.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..f8d756e5e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,25 @@ 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 + + for person in people: + Person(person["name"], person["age"]) + + for person in people: + if "wife" in person and person["wife"] is not None: + wife = Person.people[person["wife"]] + Person.people[person["name"]].wife = wife + + if "husband" in person and person["husband"] is not None: + husband = Person.people[person["husband"]] + Person.people[person["name"]].husband = husband + + return [person for person in Person.people.values()] From 07abe700bd1b08d1d1ded14f2ba73b3c6acbd60a Mon Sep 17 00:00:00 2001 From: Oleksandr Asauliak Date: Tue, 19 Sep 2023 18:49:47 +0300 Subject: [PATCH 2/2] v1.1 --- app/main.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/main.py b/app/main.py index f8d756e5e..aa08fafce 100644 --- a/app/main.py +++ b/app/main.py @@ -9,17 +9,24 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: + person_list = [] for person in people: - Person(person["name"], person["age"]) - - for person in people: - if "wife" in person and person["wife"] is not None: - wife = Person.people[person["wife"]] - Person.people[person["name"]].wife = wife - - if "husband" in person and person["husband"] is not None: - husband = Person.people[person["husband"]] - Person.people[person["name"]].husband = husband - - return [person for person in Person.people.values()] + profile = Person(person["name"], person["age"]) + person_list.append(profile) + + if person.get("wife"): + wife_name = person["wife"] + if wife_name in Person.people: + wife = Person.people[person["wife"]] + profile.wife = wife + wife.husband = profile + + if person.get("husband"): + husband_name = person["husband"] + if husband_name in Person.people: + husband = Person.people[person["husband"]] + profile.husband = husband + husband.wife = profile + + return person_list