From f8e43e28fbce695df30a136407a025750655aa6c Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 14 Nov 2023 22:52:18 +0200 Subject: [PATCH 1/3] Solution --- app/main.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..996adc132 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,31 @@ class Person: - # write your code here - pass + people = {} + + def __init__(self, name: str, age: int) -> None: + self.name = name + self.age = age + Person.people[self.name] = self def create_person_list(people: list) -> list: - # write your code here - pass + list_of_people = [] + for character in people: + list_of_people.append( + Person( + name=character["name"], + age=character["age"] + ) + ) + for index in range(len(list_of_people)): + for _ in range(index + 1): + if "wife" in people[index]: + if not people[index]["wife"] is None: + list_of_people[index].wife = Person.people[ + people[index]["wife"] + ] + if "husband" in people[index]: + if not people[index]["husband"] is None: + list_of_people[index].husband = Person.people[ + people[index]["husband"] + ] + return list_of_people From 93ae2ec6cfc33957e8b92995d2d6e7947ff4a031 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 15 Nov 2023 01:26:48 +0200 Subject: [PATCH 2/3] Solution --- app/main.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/main.py b/app/main.py index 996adc132..5194f9854 100644 --- a/app/main.py +++ b/app/main.py @@ -17,15 +17,14 @@ def create_person_list(people: list) -> list: ) ) for index in range(len(list_of_people)): - for _ in range(index + 1): - if "wife" in people[index]: - if not people[index]["wife"] is None: - list_of_people[index].wife = Person.people[ - people[index]["wife"] - ] - if "husband" in people[index]: - if not people[index]["husband"] is None: - list_of_people[index].husband = Person.people[ - people[index]["husband"] - ] + if "wife" in people[index]: + if people[index]["wife"]: + list_of_people[index].wife = Person.people[ + people[index]["wife"] + ] + if "husband" in people[index]: + if people[index]["husband"]: + list_of_people[index].husband = Person.people[ + people[index]["husband"] + ] return list_of_people From 1f4ffa51332d45ddb3da0a822d68bf13d15906c6 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 15 Nov 2023 14:14:54 +0200 Subject: [PATCH 3/3] Solution --- app/main.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/main.py b/app/main.py index 5194f9854..0879ffd4e 100644 --- a/app/main.py +++ b/app/main.py @@ -8,23 +8,23 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: - list_of_people = [] - for character in people: - list_of_people.append( - Person( - name=character["name"], - age=character["age"] - ) - ) + list_of_people = [ + Person(name=character["name"], age=character["age"]) + for character in people + ] for index in range(len(list_of_people)): - if "wife" in people[index]: - if people[index]["wife"]: - list_of_people[index].wife = Person.people[ - people[index]["wife"] - ] - if "husband" in people[index]: - if people[index]["husband"]: - list_of_people[index].husband = Person.people[ - people[index]["husband"] - ] + wife_name = people[index].get("wife") + + husband_name = people[index].get("husband") + + if wife_name: + list_of_people[index].wife = Person.people[ + people[index]["wife"] + ] + + if husband_name: + list_of_people[index].husband = Person.people[ + people[index]["husband"] + ] + return list_of_people