From beb7ffb48c6217691de08fadf7d1e0d77bb98a3e Mon Sep 17 00:00:00 2001 From: Dmytro Bulavka Date: Mon, 2 Dec 2024 16:43:33 +0200 Subject: [PATCH 1/3] Solution --- app/main.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..c20152229 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,26 @@ 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 + + person_list = [] + + for person_data in people: + person = Person(name=person_data["name"], age=person_data["age"]) + person_list.append(person) + + for person_data in people: + person = Person.people[person_data["name"]] + if "wife" in person_data and person_data["wife"]: + person.wife = Person.people[person_data["wife"]] + elif "husband" in person_data and person_data["husband"]: + person.husband = Person.people[person_data["husband"]] + + return person_list From 9d2eec08256021a9ce3c586ba0819c823ef74d0b Mon Sep 17 00:00:00 2001 From: Dmytro Bulavka Date: Wed, 4 Dec 2024 14:17:42 +0200 Subject: [PATCH 2/3] Mentor's comment fix --- app/main.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index c20152229..b11636e45 100644 --- a/app/main.py +++ b/app/main.py @@ -1,26 +1,22 @@ class Person: people = {} - def __init__(self, name: str, age: int) -> None: + def __init__(self, name: str, age: int): self.name = name self.age = age - Person.people[name] = self def create_person_list(people: list) -> list: - - person_list = [] - - for person_data in people: - person = Person(name=person_data["name"], age=person_data["age"]) - person_list.append(person) - - for person_data in people: - person = Person.people[person_data["name"]] - if "wife" in person_data and person_data["wife"]: - person.wife = Person.people[person_data["wife"]] - elif "husband" in person_data and person_data["husband"]: - person.husband = Person.people[person_data["husband"]] + person_list = [Person(data["name"], data["age"]) for data in people] + + for data in people: + person = Person.people[data["name"]] + if (wife_name := data.get("wife")): + person.wife = Person.people[wife_name] + person.wife.husband = person + if (husband_name := data.get("husband")): + person.husband = Person.people[husband_name] + person.husband.wife = person return person_list From 65e66db5fc5ebf83311a4f465db80c837ffe3d37 Mon Sep 17 00:00:00 2001 From: Dmytro Bulavka Date: Wed, 4 Dec 2024 14:19:05 +0200 Subject: [PATCH 3/3] Mentor's comment fix --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b11636e45..0e4ca9aec 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ class Person: people = {} - def __init__(self, name: str, age: int): + def __init__(self, name: str, age: int) -> None: self.name = name self.age = age Person.people[name] = self