From 443bad138ca7a0c2f93402649a506af40420f531 Mon Sep 17 00:00:00 2001 From: Your NameMykola Date: Wed, 4 Dec 2024 11:32:19 +0200 Subject: [PATCH 1/2] first solution. all tests passed. flake8 app passed --- app/main.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..02e297877 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,24 @@ 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 + persons = [] + + for person_inf in people: + person = Person(person_inf["name"], person_inf["age"]) + persons.append(person) + + for person_inf in people: + person = Person.people[person_inf["name"]] + if person_inf.get("wife"): + person.wife = Person.people[person_inf["wife"]] + if person_inf.get("husband"): + person.husband = Person.people[person_inf["husband"]] + + return persons From 4ae4bdbe9a26cd081e4b838cb0f375f6477c8c9a Mon Sep 17 00:00:00 2001 From: Your NameMykola Date: Mon, 9 Dec 2024 20:47:09 +0200 Subject: [PATCH 2/2] refactored according to the mentors comments. all tests passed. flake8 app passed --- app/main.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/main.py b/app/main.py index 02e297877..12b915f23 100644 --- a/app/main.py +++ b/app/main.py @@ -7,18 +7,15 @@ def __init__(self, name: str, age: int) -> None: Person.people[name] = self -def create_person_list(people: list) -> list: - persons = [] +def create_person_list(people: list[dict]) -> list["Person"]: + persons = [Person(person["name"], person["age"]) + for person in people] - for person_inf in people: - person = Person(person_inf["name"], person_inf["age"]) - persons.append(person) - - for person_inf in people: - person = Person.people[person_inf["name"]] - if person_inf.get("wife"): - person.wife = Person.people[person_inf["wife"]] - if person_inf.get("husband"): - person.husband = Person.people[person_inf["husband"]] + for person_data in people: + person = Person.people[person_data["name"]] + if person_data.get("wife"): + person.wife = Person.people[person_data["wife"]] + if person_data.get("husband"): + person.husband = Person.people[person_data["husband"]] return persons