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

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
27 changes: 23 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
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 dictionary with names as keys (Person.people) can lead to issues if two people have the same name, as one entry will overwrite the other. Consider using unique identifiers for each person.

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 Person.people can lead to issues if multiple instances are created or if the function is called multiple times. Consider using instance-level storage or ensuring unique keys.


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

Choose a reason for hiding this comment

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

Using name as a key in Person.people can cause overwriting if two people have the same name. Consider using a unique identifier for each person.



def create_person_list(people: list) -> list:
# write your code here
pass
Person.people = {}

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

for person in people:
name = person["name"]
if "wife" in person and person["wife"]:
Person.people[name].wife = Person.people[person["wife"]]
Person.people[person["wife"]].husband = Person.people[name]
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.

Ensure that person['wife'] exists in Person.people before attempting to access it. This will prevent potential KeyError exceptions.


if "husband" in person and person["husband"]:
Person.people[name].husband = Person.people[person["husband"]]
Person.people[person["husband"]].wife = Person.people[name]
Comment on lines +23 to +25

Choose a reason for hiding this comment

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

Ensure that person['husband'] exists in Person.people before attempting to access it. This will prevent potential KeyError exceptions.


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