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

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

Solution #1614

wants to merge 3 commits into from

Conversation

buhova
Copy link

@buhova buhova commented Dec 4, 2024

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.

Your implementation is on the right track, but there are a couple of improvements needed to fully meet the task requirements. Specifically, using the dict.get() method instead of checking for keys directly will help avoid potential errors and make your code cleaner. Additionally, refactoring your loop to use list comprehension will enhance readability and efficiency. Keep up the great work, and with these changes, your code will be even better! 😊

✨ 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
Comment on lines 11 to 13
people_list = []
for person_data in people:
people_list.append(Person(person_data["name"], person_data["age"]))

Choose a reason for hiding this comment

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

Consider using a list comprehension to create people_list. This will make the code more concise and align with the checklist recommendation: 'it is recommended to use list comprehension rather than traditional for loops' .

app/main.py Outdated
Comment on lines 17 to 20
if "wife" in person_data and person_data["wife"]:
person.wife = Person.people[person_data["wife"]]
elif "husband" in person_data and person_data["husband"]:
person.husband = Person.people[person_data["husband"]]

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 using in and accessing them directly, use the dict.get() method. This approach simplifies the code and avoids potential KeyError exceptions, making it cleaner and more concise .

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 effectively used dictionary access and list comprehension. However, there's room for improvement in simplifying the logic for setting the wife and husband attributes. Since you're already using dict.get(), you can directly assign its result to these attributes, as it will return None if the key doesn't exist. This will make your code cleaner and more robust. Keep up the good work, and make sure to address this simplification in future projects to enhance your coding skills further! 🚀

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

Comment on lines +16 to +19
if person_data.get("wife") and person_data["wife"]:
person.wife = Person.people.get(person_data["wife"])
elif person_data.get("husband") and person_data["husband"]:
person.husband = Person.people.get(person_data["husband"])

Choose a reason for hiding this comment

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

The logic for setting the wife and husband attributes is correct, but it could be simplified. Since you're already using dict.get(), you don't need to check person_data['wife'] or person_data['husband'] again. You can directly assign the result of Person.people.get() to person.wife or person.husband, as dict.get() will return None if the key doesn't exist, which is a valid assignment.

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