From b565bb4bc5057500cadb39a1139cab156834dc37 Mon Sep 17 00:00:00 2001 From: xboris Date: Thu, 26 Oct 2023 00:26:18 +0300 Subject: [PATCH 1/2] 'solution' --- app/main.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..7ee108c49 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,28 @@ class Person: - # write your code here - pass + + people = {} + + def __init__(self, name: str, age: int) -> None: + self.name = name + self.age = age + self.people[name] = self def create_person_list(people: list) -> list: - # write your code here - pass + + people_list = [Person(name=person["name"], age=person["age"]) for person in people] + for person in people: + current_person = Person.people[person["name"]] + if person.get("wife"): + current_person.wife = Person.people[person["wife"]] + if person.get("husband"): + current_person.husband = Person.people[person["husband"]] + + return people_list + +people = [ + {"name": "Ross", "age": 30, "wife": "Rachel"}, + {"name": "Joey", "age": 29, "wife": None}, + {"name": "Rachel", "age": 28, "husband": "Ross"} +] + From ca851c7270c24cd285594e61907cabb80de1fb29 Mon Sep 17 00:00:00 2001 From: xboris Date: Thu, 26 Oct 2023 00:27:14 +0300 Subject: [PATCH 2/2] 'solution' --- app/main.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index 7ee108c49..73175320e 100644 --- a/app/main.py +++ b/app/main.py @@ -10,7 +10,8 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: - people_list = [Person(name=person["name"], age=person["age"]) for person in people] + people_list = [Person(name=person["name"], + age=person["age"]) for person in people] for person in people: current_person = Person.people[person["name"]] if person.get("wife"): @@ -19,10 +20,3 @@ def create_person_list(people: list) -> list: current_person.husband = Person.people[person["husband"]] return people_list - -people = [ - {"name": "Ross", "age": 30, "wife": "Rachel"}, - {"name": "Joey", "age": 29, "wife": None}, - {"name": "Rachel", "age": 28, "husband": "Ross"} -] -