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

Open
wants to merge 2 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
22 changes: 18 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
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 defined as a class variable. This means it will be shared across all instances of the Person class. If this is not the intended behavior, consider using an instance variable instead.

Choose a reason for hiding this comment

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

The people dictionary is defined as a class variable, which means it is shared across all instances of the Person class. If this shared behavior is not intended, consider using an instance variable instead to avoid potential issues.


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
for result in people:
Person(result["name"], result["age"])
for result in people:
result_people = Person.people[result["name"]]
if "wife" in result and result["wife"] is not None:
result_people.wife = Person.people[result["wife"]]
Comment on lines +15 to +16

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 key will always correspond to a valid name in the Person.people dictionary. This can lead to a KeyError if the name is not found. Consider adding a check to ensure the name exists in the dictionary before accessing it.


if "husband" in result and result["husband"] is not None:
if result["husband"] in Person.people:
result_people.husband = Person.people[result["husband"]]
Comment on lines +19 to +20

Choose a reason for hiding this comment

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

While there is a check for the husband key in the Person.people dictionary, the code still assumes that the key will always correspond to a valid name. Ensure that the input data is validated or handle potential KeyError exceptions appropriately.


return list(Person.people.values())
Loading