Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #811

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
from typing import Optional, List


class Person:
# write your code here
pass
people = {}

def __init__(self, name: str,
age: int,
spouse: Optional["Person"] = None) -> None:
Comment on lines +7 to +9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

self.name = name
self.age = age
self.spouse = spouse
Person.people[name] = self
self.wife = None
self.husband = None


def create_person_list(people_data: List[dict]) -> List[Person]:
person_list = []

for person_data in people_data:
name: str = person_data["name"]
age: int = person_data["age"]
spouse_name: Optional[str] = (person_data.get("wife")
or person_data.get("husband"))

spouse: Optional[Person] = (Person.people.get(spouse_name)
if spouse_name else None)

person = Person(name, age, spouse)
person_list.append(person)

if spouse:
if "wife" in person_data:
person.wife = spouse
spouse.husband = person
elif "husband" in person_data:
person.husband = spouse
spouse.wife = person

def create_person_list(people: list) -> list:
# write your code here
pass
return person_list
Loading