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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #1642

wants to merge 2 commits into from

Conversation

lozovoyDanil
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Shared people Dictionary: The people dictionary is currently a class variable, which means it is shared across all instances of the Person class. This might not be the intended behavior, as it can lead to unexpected results when managing multiple Person instances. Consider moving the people dictionary to an instance variable by defining it within the __init__ method.

  2. Clearing the people Dictionary: 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.

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 = {}

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
Comment on lines 10 to 22
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]

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Shared people Dictionary: The people dictionary is currently 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.

  2. Clearing the people Dictionary: The create_person_list function does not clear the people 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.

  3. Use of dict.get() Method: Simplify your code and avoid potential KeyError exceptions by using the dict.get() method instead of explicit key checks like "wife" in person and person["wife"] is not None.

  4. 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 = {}

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants