From eefa5e437494f7c38475a88cdc251e12d4ca2290 Mon Sep 17 00:00:00 2001 From: VladKrit-commits Date: Tue, 12 Sep 2023 22:05:24 +0300 Subject: [PATCH] Solutin_py_person_class --- app/main.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f6bcaa1dd..9f94a7f03 100644 --- a/app/main.py +++ b/app/main.py @@ -1,8 +1,23 @@ class Person: - # write your code here - pass + people = {} + + def __init__(self, name: str, age: str) -> None: + self.name = name + self.age = age + Person.people[name] = self def create_person_list(people: list) -> list: - # write your code here - pass + result = [Person(person["name"], person["age"]) for person in people] + + for person in people: + human = Person.people[person["name"]] + if "husband" in person and person["husband"]: + husband_to_add = Person.people[person["husband"]] + setattr(human, "husband", husband_to_add) + + elif "wife" in person and person["wife"]: + wife_to_add = Person.people[person["wife"]] + setattr(human, "wife", wife_to_add) + + return result