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 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
23 changes: 19 additions & 4 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 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
for person in people:
name, age = person["name"], person["age"]
Person(name, age)

for person in people:
name = person["name"]
spouse = person.get("wife") or person.get("husband")
if spouse:
setattr(Person.people[name],
"wife" if "wife" in person else "husband",
Person.people[spouse])

return list(Person.people.values())

Choose a reason for hiding this comment

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

The function create_person_list modifies the class-level dictionary Person.people. If this function is called multiple times, it will accumulate people from all calls, which might not be the intended behavior. Consider resetting Person.people at the start of the function or using an instance-level dictionary.

Loading