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

Open
wants to merge 1 commit 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
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 = {}

Choose a reason for hiding this comment

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

Using a class variable people to store instances of Person by name assumes that names are unique. If two people have the same name, the latter will overwrite the former in the dictionary. Consider using a unique identifier for each person.


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

def __repr__(self) -> str:
return f"Person(name={self.name}, age={self.age})"


def create_person_list(people: list) -> list:
# write your code here
pass
persons = []

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

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

if "wife" in data and data["wife"] is not None:
wife_name = data["wife"]
if wife_name in Person.people:
person.wife = Person.people[wife_name]
Comment on lines +25 to +28

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 name exists in the Person.people dictionary. If the name is not found, it will silently fail to set the wife attribute. Consider adding error handling or logging to handle cases where the wife name is not found.


if "husband" in data and data["husband"] is not None:
husband_name = data["husband"]
if husband_name in Person.people:
person.husband = Person.people[husband_name]
Comment on lines +30 to +33

Choose a reason for hiding this comment

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

Similar to the wife attribute, the code assumes that the husband name exists in the Person.people dictionary. If the name is not found, it will silently fail to set the husband attribute. Consider adding error handling or logging to handle cases where the husband name is not found.


return persons