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

Complite #1654

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
24 changes: 20 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
class Person:
# write your code here
pass
people = {}
meff-p 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.

The use of a class-level dictionary people to store instances by name assumes that all names are unique. This can lead to incorrect spouse assignments if names are not unique. Consider using unique identifiers or implementing a strategy to handle name collisions.


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.

Assigning Person.people[name] = self without checking for existing entries can lead to overwriting existing instances if duplicate names are provided. Consider checking for duplicates or using unique identifiers.



def create_person_list(people: list) -> list:
# write your code here
pass
person_people = []
for person_dict in people:
person = Person(name=person_dict["name"], age=person_dict["age"])
person_people.append(person)

for person_dict in people:
person = Person.people[person_dict["name"]]
meff-p marked this conversation as resolved.
Show resolved Hide resolved

if "wife" in person_dict and person_dict["wife"] is not None:
person.wife = Person.people[person_dict["wife"]]
elif "husband" in person_dict and person_dict["husband"] is not None:
person.husband = Person.people[person_dict["husband"]]
meff-p marked this conversation as resolved.
Show resolved Hide resolved

return person_people
Loading