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 1 commit
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 = {}

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 peoples in people:

Choose a reason for hiding this comment

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

The variable name peoples is misleading as it suggests a plural form. Consider renaming it to person_data or something similar to better reflect its purpose.

Person(peoples["name"], peoples["age"])
for peoples in people:

Choose a reason for hiding this comment

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

Similar to line 11, the variable name peoples is misleading. Consider renaming it to person_data or something similar.

result_people = Person.people[peoples["name"]]
if "wife" in peoples and peoples["wife"] is not None:
result_people.wife = Person.people[peoples["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 key in the dictionary corresponds to a valid name in the Person.people dictionary. Ensure that the input data is validated or handle potential KeyError exceptions.


if "husband" in peoples and peoples["husband"] is not None:
result_people.husband = Person.people[peoples["husband"]]

Choose a reason for hiding this comment

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

Similar to line 16, ensure that the husband key corresponds to a valid name in the Person.people dictionary to avoid KeyError exceptions.


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