-
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 #1642
base: master
Are you sure you want to change the base?
Solution #1642
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 of the Person
class and the create_person_list
function is mostly on point, there are a couple of critical issues that need to be addressed before we can approve it:
-
Shared
people
Dictionary: Thepeople
dictionary is currently a class variable, which means it is shared across all instances of thePerson
class. This might not be the intended behavior, as it can lead to unexpected results when managing multiplePerson
instances. Consider moving thepeople
dictionary to an instance variable by defining it within the__init__
method. -
Clearing the
people
Dictionary: Thecreate_person_list
function does not clear thepeople
dictionary before adding new entries. This could lead to incorrect results if the function is called multiple times with different data. Make sure to clear the dictionary at the start of this function to ensure it only contains the current list of people.
Once these issues are resolved, your code will be more robust and aligned with the task requirements. Keep up the great work, and feel free to reach out if you have any questions or need further assistance! 🚀
✨ 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.
app/main.py
Outdated
@@ -1,8 +1,22 @@ | |||
class Person: | |||
# write your code here | |||
pass | |||
people: dict = {} |
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 people
dictionary is defined as a class variable, meaning it is shared across all instances of the Person
class. If you intend for each Person
instance to have its own people
dictionary, you should define it within the __init__
method instead.
app/main.py
Outdated
def create_person_list(people: list) -> list: | ||
# write your code here | ||
pass | ||
for person in people: | ||
Person(person["name"], person["age"]) | ||
|
||
for person in people: | ||
current = Person.people[person["name"]] | ||
|
||
if "wife" in person and person["wife"] is not None: | ||
current.wife = Person.people[person["wife"]] | ||
if "husband" in person and person["husband"] is not None: | ||
current.husband = Person.people[person["husband"]] | ||
|
||
return [Person.people[name] for name in Person.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.
The create_person_list
function does not clear the Person.people
dictionary before adding new entries. This could lead to incorrect results if the function is called multiple times with different data. Consider clearing the dictionary at the start of this function to ensure it only contains the current list of 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.
Great job on implementing the Person
class and the create_person_list
function! 🎉 While your code meets the basic requirements, there are a few critical issues that need attention to ensure it functions correctly:
-
Shared
people
Dictionary: Thepeople
dictionary is currently a class variable, which means it is shared across all instances of thePerson
class. This can lead to unexpected behavior when managing multiplePerson
instances. Consider moving thepeople
dictionary to an instance variable by defining it within the__init__
method. -
Clearing the
people
Dictionary: Thecreate_person_list
function does not clear thepeople
dictionary before adding new entries. This could result in incorrect data if the function is called multiple times with different inputs. Make sure to clear the dictionary at the start of this function to ensure it only contains the current list of people. -
Use of
dict.get()
Method: Simplify your code and avoid potentialKeyError
exceptions by using thedict.get()
method instead of explicit key checks like"wife" in person and person["wife"] is not None
. -
List Comprehension: Consider using list comprehension to create a list of instances from a collection, as it is more concise and aligns with best practices.
These improvements will help you avoid potential issues and enhance the functionality 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,24 @@ | |||
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.
The people
dictionary is a class variable, which means it is shared across all instances of the Person
class. This can lead to unexpected behavior when managing multiple Person
instances. Consider moving the people
dictionary to an instance variable by defining it within the __init__
method.
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: |
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 create_person_list
function does not clear the people
dictionary before adding new entries. This could lead to incorrect results if the function is called multiple times with different data. Make sure to clear the dictionary at the start of this function to ensure it only contains the current list of people.
No description provided.