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

'help' #1625

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

'help' #1625

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

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

def set_relationships(self, people: dict) -> dict:
if "wife" in people and people["wife"]:
self.wife = Person.people[people["wife"]]

Choose a reason for hiding this comment

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

The code assumes that the wife's name exists in Person.people. Consider adding a check to ensure the name exists before accessing it to avoid potential KeyError.

elif "wife" in people:
if hasattr(self, "wife"):
del self.wife

if "husband" in people and people["husband"]:
self.husband = Person.people[people["husband"]]

Choose a reason for hiding this comment

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

Similar to the wife's check, ensure that the husband's name exists in Person.people before accessing it to prevent KeyError.

elif "husband" in people:
if hasattr(self, "husband"):
del self.husband


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

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

Choose a reason for hiding this comment

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

Ensure that the person's name exists in Person.people before accessing it to avoid potential KeyError. This is important for robustness, especially if the input data might be incomplete or incorrect.

person.set_relationships(person_data)

return person_objects
Loading