From ce3bdb99f7c7fc24e41e4cde7b324b421490a3d7 Mon Sep 17 00:00:00 2001 From: Tymur Shmorhun Date: Mon, 16 Oct 2023 23:31:17 +0300 Subject: [PATCH 1/5] Solution --- app/main.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..3767de899 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 + + person_list = [] + + for dc in people: + _ = Person(dc["name"], dc["age"]) + + for dc in people: + + if "wife" in dc: + if dc["wife"] is not None: + Person.people[dc["name"]].wife = Person.people[dc["wife"]] + + if "husband" in dc: + if dc["husband"] is not None: + Person.people[dc["name"]].husband = ( + Person.people)[dc["husband"]] + + person_list.append(Person.people[dc["name"]]) + + return person_list From 5c3f1ba67f97087ce7b1ba4f050b62382c56b53b Mon Sep 17 00:00:00 2001 From: Tymur Shmorhun Date: Fri, 20 Oct 2023 00:48:07 +0300 Subject: [PATCH 2/5] Solution --- app/main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/main.py b/app/main.py index 3767de899..dda4f0fcb 100644 --- a/app/main.py +++ b/app/main.py @@ -9,23 +9,22 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: - person_list = [] - for dc in people: - _ = Person(dc["name"], dc["age"]) + _ = [Person(dc["name"], dc["age"]) for dc in people] for dc in people: - if "wife" in dc: - if dc["wife"] is not None: + if dc.get("wife"): Person.people[dc["name"]].wife = Person.people[dc["wife"]] - if "husband" in dc: - if dc["husband"] is not None: + if dc.get("husband"): Person.people[dc["name"]].husband = ( Person.people)[dc["husband"]] person_list.append(Person.people[dc["name"]]) + for i in person_list: + print(i.name) + return person_list From 3c9d050129636a1715b77f8fb0c17565129d9870 Mon Sep 17 00:00:00 2001 From: Tymur Shmorhun Date: Fri, 20 Oct 2023 00:59:07 +0300 Subject: [PATCH 3/5] Solution with list comprehension and .get method --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index dda4f0fcb..f9874e6dd 100644 --- a/app/main.py +++ b/app/main.py @@ -16,11 +16,11 @@ def create_person_list(people: list) -> list: for dc in people: if dc.get("wife"): - Person.people[dc["name"]].wife = Person.people[dc["wife"]] + Person.people[dc["name"]].wife = Person.people[dc["wife"]] if dc.get("husband"): - Person.people[dc["name"]].husband = ( - Person.people)[dc["husband"]] + Person.people[dc["name"]].husband = ( + Person.people)[dc["husband"]] person_list.append(Person.people[dc["name"]]) From 0809327e98a60635d29c20d9dddc8ef064270e1e Mon Sep 17 00:00:00 2001 From: Tymur Shmorhun Date: Mon, 23 Oct 2023 00:41:17 +0300 Subject: [PATCH 4/5] Solution with list comprehension and .get method# --- app/main.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/main.py b/app/main.py index f9874e6dd..1beae1203 100644 --- a/app/main.py +++ b/app/main.py @@ -24,7 +24,4 @@ def create_person_list(people: list) -> list: person_list.append(Person.people[dc["name"]]) - for i in person_list: - print(i.name) - return person_list From de7da9fa24ebc55c4de8e8bcee159189ac85be59 Mon Sep 17 00:00:00 2001 From: Tymur Shmorhun Date: Mon, 23 Oct 2023 18:05:55 +0300 Subject: [PATCH 5/5] Solution with list comprehension and .get method# --- app/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 1beae1203..ca94a16fc 100644 --- a/app/main.py +++ b/app/main.py @@ -11,7 +11,7 @@ def __init__(self, name: str, age: int) -> None: def create_person_list(people: list) -> list: person_list = [] - _ = [Person(dc["name"], dc["age"]) for dc in people] + person_list = [Person(dc["name"], dc["age"]) for dc in people] for dc in people: @@ -22,6 +22,4 @@ def create_person_list(people: list) -> list: Person.people[dc["name"]].husband = ( Person.people)[dc["husband"]] - person_list.append(Person.people[dc["name"]]) - return person_list