-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: master
Are you sure you want to change the base?
Solution #1643
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this Pull Request! 😊 While your implementation meets many of the task requirements, there are a couple of critical issues that need to be addressed before we can approve it:
-
Class-Level Dictionary Modification: The
create_person_list
function modifies the class-level dictionaryPerson.people
. This can lead to unintended behavior if the function is called multiple times, as it will accumulate entries from all calls. Consider resettingPerson.people
at the start of the function or using an instance-level dictionary to avoid this issue. -
Potential Overwriting in
Person.people
: Using names as keys in thePerson.people
dictionary can cause entries to be overwritten if two people have the same name. To prevent this, consider using unique identifiers for each person instead of names.
Addressing these issues will make your code more robust and prevent potential bugs in the future. Keep up the great work, and I look forward to seeing your improvements! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
@@ -1,8 +1,23 @@ | |||
class Person: | |||
# write your code here | |||
pass | |||
people = {} |
There was a problem hiding this comment.
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.
app/main.py
Outdated
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great job on updating the code in app/main.py
! 🎉 You've made significant progress in addressing the issues previously mentioned. Here are some key points and suggestions for further improvement:
-
Class-Level Dictionary Modification: You've correctly reset the
Person.people
dictionary at the start of thecreate_person_list
function, which is essential to avoid accumulation from multiple calls. However, using names as keys can still lead to overwriting if two people share the same name. Consider using unique identifiers to prevent this issue. -
Relationship Assignment: The current implementation assumes that names for 'wife' and 'husband' exist in the
Person.people
dictionary, which could lead toKeyError
exceptions if a name is not found. Ensure these names are validated or handled properly to enhance robustness. -
Use of
dict.get()
: While not critical, usingdict.get()
for accessing dictionary values can make your code cleaner and more concise. It's something to consider for future improvements.
Overall, your solution meets the task requirements and constraints. The decision to approve this pull request is made to help you move forward with your learning journey. Please review the comments to improve your code further. Addressing these critical issues will enhance the functionality and robustness of your code. Keep up the great work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -1,8 +1,27 @@ | |||
class Person: | |||
# write your code here | |||
pass | |||
people = {} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
if "wife" in person and person["wife"]: | ||
Person.people[name].wife = Person.people[person["wife"]] | ||
Person.people[person["wife"]].husband = Person.people[name] |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
No description provided.