From 9691ed719f6c60c17cb1fec0339122bb0c645081 Mon Sep 17 00:00:00 2001 From: Adrianna Regulska Date: Thu, 12 Dec 2024 23:10:55 +0100 Subject: [PATCH] Solution --- app/main.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..dc770f22f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,35 @@ class Person: - # write your code here - pass + people = {} + + def __init__(self, name: str, age: int) -> None: + self.name = name + self.age = age + self.wife = None + self.husband = None + Person.people[name] = self + + def __repr__(self) -> str: + return f"Person(name={self.name}, age={self.age})" def create_person_list(people: list) -> list: - # write your code here - pass + persons = [] + + for data in people: + person = Person(data["name"], data["age"]) + persons.append(person) + + for data in people: + person = Person.people[data["name"]] + + if "wife" in data and data["wife"] is not None: + wife_name = data["wife"] + if wife_name in Person.people: + person.wife = Person.people[wife_name] + + if "husband" in data and data["husband"] is not None: + husband_name = data["husband"] + if husband_name in Person.people: + person.husband = Person.people[husband_name] + + return persons