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

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
25 changes: 20 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
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-level dictionary people to store instances by name can lead to issues if multiple people have the same name. Consider using unique identifiers for each person.


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

def create_person_list(people: list) -> None:
person_list = []
for person in people:
person_instance = Person(name=person["name"], age=person["age"])
person_list.append(person_instance)

for person in people:
person_instance = Person.people[person["name"]]
if "wife" in person and person["wife"] is not None:
person_instance.wife = Person.people[person["wife"]]
elif "husband" in person and person["husband"] is not None:
person_instance.husband = Person.people[person["husband"]]
Comment on lines +19 to +21

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 spouse (wife/husband) is already created and present in the Person.people dictionary. Ensure that the input list people is ordered or structured such that all referenced spouses are created before they are assigned.


return person_list
Loading