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

Update main.py #1636

Closed
wants to merge 2 commits into from
Closed

Update main.py #1636

wants to merge 2 commits into from

Conversation

DaniaK123
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.


Hello! 😊 It looks like your implementation of the Person class and the create_person_list function is mostly on the right track, but there are a couple of important improvements needed to fully meet the task requirements:

  1. List Comprehension: The task checklist recommends using list comprehension for creating lists from collections. Refactoring your create_person_list function to use list comprehension instead of a traditional for loop will make your code cleaner and more concise.

  2. Accessing Dictionary Values: Instead of checking for the presence of keys like "wife" or "husband" using if statements, it's better to use the dict.get() method. This approach not only simplifies your code but also prevents potential KeyError exceptions.

These changes are important to ensure your code aligns with best practices and the task requirements. Once you make these adjustments, your solution should be good to go! Keep up the great work, and don't hesitate to reach out if you have any questions. 🚀

✨ 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 10 to 14
def create_person_list(people: list) -> None:
person_list = []
for person in people:
person_instance = Person(name=person["name"], age=person["age"])
person_list.append(person_instance)

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 person_list. This aligns with the checklist recommendation to use list comprehension when creating a list of instances from a collection.

app/main.py Outdated
Comment on lines 18 to 21
if "wife" in person and person["wife"] is not None:
person_instance.wife = Person.people[person["wife"]]
elif "husband" in person and person["husband"] is not None:
person_instance.husband = Person.people[person["husband"]]

Choose a reason for hiding this comment

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

Instead of explicitly checking for the presence of 'wife' or 'husband' keys, consider using the dict.get() method. This approach simplifies the code and avoids potential KeyError exceptions.

@DaniaK123 DaniaK123 closed this Dec 14, 2024
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