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 #1614

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
21 changes: 17 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
class Person:
# write your code here
pass
people = {}

def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
Person.people[name] = self


def create_person_list(people: list) -> list:
# write your code here
pass
people_list = [Person(person_data["name"], person_data["age"])
for person_data in people]

for person_data in people:
person = Person.people.get(person_data["name"])
if person_data.get("wife") and person_data["wife"]:
person.wife = Person.people.get(person_data["wife"])
elif person_data.get("husband") and person_data["husband"]:
person.husband = Person.people.get(person_data["husband"])
Comment on lines +16 to +19

Choose a reason for hiding this comment

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

The logic for setting the wife and husband attributes is correct, but it could be simplified. Since you're already using dict.get(), you don't need to check person_data['wife'] or person_data['husband'] again. You can directly assign the result of Person.people.get() to person.wife or person.husband, as dict.get() will return None if the key doesn't exist, which is a valid assignment.


return people_list
Loading