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

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

Choose a reason for hiding this comment

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

The people dictionary is used to store instances of Person by name. This approach assumes that all names are unique, which might not be the case. Consider handling potential name conflicts or using a different identifier.


def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
self.wife = None
self.husband = None

def create_person_list(people: list) -> list:
# write your code here
pass
Person.people[name] = self


def create_person_list(people_list: list) -> list:
persons = []

for one in people_list:
name = one["name"]
age = one["age"]
person = Person(name, age)
persons.append(person)

for one in people_list:
name = one["name"]
person = Person.people[name]

if "wife" in one and one["wife"]:
person.wife = Person.people.get(one["wife"])
elif "husband" in one and one["husband"]:
person.husband = Person.people.get(one["husband"])
Comment on lines +26 to +29

Choose a reason for hiding this comment

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

The logic for setting wife and husband attributes assumes that the provided names are always valid and present in the Person.people dictionary. Consider adding error handling or validation to ensure that the names exist in the dictionary before accessing them.


return persons
Loading