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' #1626

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

'Solution' #1626

wants to merge 2 commits into from

Conversation

Dmitriy527
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 correct, there are a few critical issues that need to be addressed to meet the task requirements fully:

  1. Dictionary Access: Instead of checking for keys explicitly, use the dict.get() method. This will simplify your code and prevent potential KeyError exceptions.

  2. Variable Naming: The variable people inside the loop shadows the input parameter people of the function create_person_list. This can lead to confusion and potential bugs. Consider renaming it to something more descriptive.

  3. Nested if Statements: Your code contains nested if statements that can be simplified using logical operators like and. This will make your code cleaner and more readable.

These changes are important to ensure the code is robust and adheres to best practices. Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need any help. 🚀

✨ 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,33 @@
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 correctly defined as a class attribute, but ensure that it is used consistently throughout the class to store instances by their name as required by the task description.

app/main.py Outdated
pass
our_list = []
for human in people:
people = Person(human["name"], human["age"])

Choose a reason for hiding this comment

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

The variable people here shadows the input parameter people of the function create_person_list. Consider renaming this variable to avoid confusion and potential bugs.

app/main.py Outdated
Comment on lines 14 to 15
if "husband" in human:
if human["husband"] is not None:

Choose a reason for hiding this comment

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

According to the checklist, you should avoid nested if statements by using logical operators like and. You can combine these two conditions into one using and.

app/main.py Outdated
Comment on lines 17 to 18
if "wife" in human:
if human["wife"] is not None:

Choose a reason for hiding this comment

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

Similar to the previous comment, you can combine these two conditions using and to avoid nested if statements.

app/main.py Outdated
Comment on lines 12 to 20
for human in people:
people = Person(human["name"], human["age"])
if "husband" in human:
if human["husband"] is not None:
people.husband = human["husband"]
if "wife" in human:
if human["wife"] is not None:
people.wife = human["wife"]
our_list.append(people)

Choose a reason for hiding this comment

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

Consider using list comprehension to create the list of Person instances from the input list of dictionaries, as recommended by the checklist.

app/main.py Outdated
Comment on lines 14 to 19
if "husband" in human:
if human["husband"] is not None:
people.husband = human["husband"]
if "wife" in human:
if human["wife"] is not None:
people.wife = human["wife"]

Choose a reason for hiding this comment

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

Instead of checking for the presence of keys explicitly, use the dict.get() method to simplify the code and avoid potential KeyError exceptions.

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! 🎉 Your code meets the task requirements and constraints, and you've made significant improvements. Here are a few points to consider for further enhancement:

  • Class Variable Issue: The people dictionary is currently a class variable, which means it is shared across all instances of the Person class. This could lead to unexpected behavior if multiple Person objects are created. Consider using an instance variable instead to avoid this issue.

  • Optimizing Attribute Assignment: When assigning husband and wife attributes, you can optimize the process by checking if the corresponding Person object already exists in our_list and directly assigning it. This will make your code more efficient.

  • Handling Missing Keys: Ensure that the human dictionary always contains the name and age keys when calling the Person class constructor. Consider adding error handling to manage cases where these keys might be missing to prevent potential KeyError exceptions.

Your code is on the right track, and addressing these points will help you avoid potential pitfalls in the future. Keep up the great work and continue learning from each iteration! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -1,8 +1,31 @@
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, meaning it is shared across all instances of the Person class. This can lead to unexpected behavior if multiple Person objects are created, as they will all share the same people dictionary. Consider using an instance variable instead.

pass
our_list = []
for human in people:
person = Person(human["name"], human["age"])

Choose a reason for hiding this comment

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

The Person class constructor is being called with human["name"] and human["age"]. Ensure that these keys are always present in the human dictionary to avoid potential KeyError exceptions. You might want to handle cases where these keys are missing.

for human in people:
person = Person(human["name"], human["age"])
if human.get("husband"):
person.husband = human["husband"]

Choose a reason for hiding this comment

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

Instead of directly assigning human["husband"] to person.husband, you could optimize this by checking if the husband is already in our_list and directly assigning the Person object if it exists.

if human.get("husband"):
person.husband = human["husband"]
if human.get("wife"):
person.wife = human["wife"]

Choose a reason for hiding this comment

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

Similar to the previous comment, consider optimizing the assignment of human["wife"] to person.wife by checking if the wife is already in our_list and directly assigning the Person object if it exists.

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