From db5e0baf68f5024dd33320986e5cb6d336818f33 Mon Sep 17 00:00:00 2001 From: Marinel444 <380978907444m@gmail.com> Date: Fri, 27 Oct 2023 20:43:25 +0300 Subject: [PATCH 1/3] Solution --- app/main.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..184e49d98 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 + self.__class__.people[name] = self def create_person_list(people: list) -> list: - # write your code here - pass + married_dict = {} + result = [] + + for item in people: + person = Person(name=item["name"], age=item["age"]) + married_dict[item["name"]] = person + result.append(person) + + for item in people: + person_obj = married_dict[item["name"]] + if item.get("wife") is not None: + person_obj.wife = married_dict[item["wife"]] + elif item.get("husband") is not None: + person_obj.husband = married_dict[item["husband"]] + + return result From 620ae431fa6ed9b5c98ac24a03dff17880aee891 Mon Sep 17 00:00:00 2001 From: Marinel444 <380978907444m@gmail.com> Date: Sat, 28 Oct 2023 15:25:18 +0300 Subject: [PATCH 2/3] removed dict --- app/main.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index 184e49d98..8d5e736ad 100644 --- a/app/main.py +++ b/app/main.py @@ -8,19 +8,12 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: - married_dict = {} - result = [] - - for item in people: - person = Person(name=item["name"], age=item["age"]) - married_dict[item["name"]] = person - result.append(person) - - for item in people: - person_obj = married_dict[item["name"]] - if item.get("wife") is not None: - person_obj.wife = married_dict[item["wife"]] - elif item.get("husband") is not None: - person_obj.husband = married_dict[item["husband"]] - + result = [Person(name=item["name"], age=item["age"]) for item in people] + for person in people: + if person.get("wife") is not None: + Person.people.get(person["name"]).wife = \ + Person.people.get(person["wife"]) + if person.get("husband") is not None: + Person.people.get(person["name"]).husband = \ + Person.people.get(person["husband"]) return result From e2e222dc4044c5510e268f7998ebf1810241ec76 Mon Sep 17 00:00:00 2001 From: Marinel444 <380978907444m@gmail.com> Date: Sat, 28 Oct 2023 15:58:12 +0300 Subject: [PATCH 3/3] add parentheses --- app/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 8d5e736ad..0f7e84eaa 100644 --- a/app/main.py +++ b/app/main.py @@ -11,9 +11,11 @@ def create_person_list(people: list) -> list: result = [Person(name=item["name"], age=item["age"]) for item in people] for person in people: if person.get("wife") is not None: - Person.people.get(person["name"]).wife = \ + Person.people.get(person["name"]).wife = ( Person.people.get(person["wife"]) + ) if person.get("husband") is not None: - Person.people.get(person["name"]).husband = \ + Person.people.get(person["name"]).husband = ( Person.people.get(person["husband"]) + ) return result