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' #1630

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
31 changes: 26 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
class Person:
# write your code here
pass
people = {}
nagafochfv marked this conversation as resolved.
Show resolved Hide resolved

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 by name can lead to issues if names are not unique. Consider using a unique identifier, such as an ID, to ensure each person is stored uniquely.


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

def create_person_list(people: list) -> list:
# write your code here
pass

def create_person_list(peoples: list) -> list:
person_list = []
for pers in peoples:
person = Person(pers["name"], pers["age"])
person_list.append(person)
for pers in peoples:
person = Person.people[pers["name"]]
if "wife" in pers and pers["wife"] is not None:
wife = Person.people.get(pers["wife"])
if wife:
setattr(person, "wife", wife)
else:
setattr(person, "wife", None)
if "husband" in pers and pers["husband"] is not None:
husband = Person.people.get(pers["husband"])
if husband:
setattr(person, "husband", husband)
else:
setattr(person, "husband", None)
Comment on lines +18 to +28

Choose a reason for hiding this comment

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

The current logic for setting 'wife' and 'husband' attributes assumes that these names will always be present in the Person.people dictionary. If a name is not found, None will be set, which might not be the desired behavior. Adding error handling for cases where the spouse is not found will make your code more robust and reliable.

return person_list
Loading