From cb6ff8c01024dd4f1b89d66c1d60458cbf2e5459 Mon Sep 17 00:00:00 2001 From: Roman Shupak Date: Wed, 13 Sep 2023 17:31:55 +0300 Subject: [PATCH] 'Solution' --- app/main.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..7cb14cb13 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 + +def create_person_list(people: list[dict]) -> list: + list_instances = [ + Person(person["name"], person["age"]) for person in people + ] + + for person in people: + if person.get("wife"): + person_name = person["name"] + wife_name = person["wife"] + Person.people[person_name].wife = Person.people.get(wife_name) + if person.get("husband"): + person_name = person["name"] + husband_name = person["husband"] + Person.people[person_name].husband = ( + Person.people.get(husband_name) + ) + return list_instances