From 7377f7e6568978da9672822cf4c841bd4e759571 Mon Sep 17 00:00:00 2001 From: Roman Peka Date: Thu, 19 Dec 2024 02:09:09 +0300 Subject: [PATCH 1/2] Solution --- app/main.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..6b6408cb9 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,23 @@ 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: + name, age = person["name"], person["age"] + Person(name, age) + + for person in people: + name = person["name"] + spouse = person.get("wife") or person.get("husband") + if spouse: + setattr(Person.people[name], + "wife" if "wife" in person else "husband", + Person.people[spouse]) + + return list(Person.people.values()) From 87afc8593c50f4a1aa228ed904ad5fa227e8e08c Mon Sep 17 00:00:00 2001 From: Roman Peka Date: Thu, 19 Dec 2024 03:05:47 +0300 Subject: [PATCH 2/2] Solution --- app/main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 6b6408cb9..14f6e6af5 100644 --- a/app/main.py +++ b/app/main.py @@ -8,16 +8,20 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: + Person.people = {} + for person in people: name, age = person["name"], person["age"] Person(name, age) for person in people: name = person["name"] - spouse = person.get("wife") or person.get("husband") - if spouse: - setattr(Person.people[name], - "wife" if "wife" in person else "husband", - Person.people[spouse]) + if "wife" in person and person["wife"]: + Person.people[name].wife = Person.people[person["wife"]] + Person.people[person["wife"]].husband = Person.people[name] + + if "husband" in person and person["husband"]: + Person.people[name].husband = Person.people[person["husband"]] + Person.people[person["husband"]].wife = Person.people[name] return list(Person.people.values())