From 7b031c71c284155e396633a72f75e21e365690c9 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 9 Dec 2024 17:50:55 +0200 Subject: [PATCH 1/2] 'Solution' --- app/main.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..51f36fde9 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,33 @@ class Person: - # write your code here - pass + people = {} + + def __init__(self, name: str, age: int) -> None: + self.name = name + self.age = age + self.people[self.name] = self def create_person_list(people: list) -> list: - # write your code here - pass + our_list = [] + for human in people: + people = Person(human["name"], human["age"]) + if "husband" in human: + if human["husband"] is not None: + people.husband = human["husband"] + if "wife" in human: + if human["wife"] is not None: + people.wife = human["wife"] + our_list.append(people) + + for item in our_list: + if hasattr(item, "wife"): + for i in our_list: + if i.name == item.wife: + item.wife = i + + if hasattr(item, "husband"): + for i in our_list: + if i.name == item.husband: + item.husband = i + + return our_list From a65087ef464d210971c9598f18f1573f1d798dd8 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 9 Dec 2024 18:25:40 +0200 Subject: [PATCH 2/2] 'Solution' --- app/main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index 51f36fde9..2465ff031 100644 --- a/app/main.py +++ b/app/main.py @@ -10,14 +10,12 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: our_list = [] for human in people: - people = Person(human["name"], human["age"]) - if "husband" in human: - if human["husband"] is not None: - people.husband = human["husband"] - if "wife" in human: - if human["wife"] is not None: - people.wife = human["wife"] - our_list.append(people) + person = Person(human["name"], human["age"]) + if human.get("husband"): + person.husband = human["husband"] + if human.get("wife"): + person.wife = human["wife"] + our_list.append(person) for item in our_list: if hasattr(item, "wife"):