-
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
Update main.py #1636
Update main.py #1636
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.
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:
-
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 traditionalfor
loop will make your code cleaner and more concise. -
Accessing Dictionary Values: Instead of checking for the presence of keys like "wife" or "husband" using
if
statements, it's better to use thedict.get()
method. This approach not only simplifies your code but also prevents potentialKeyError
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
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) |
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.
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
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"]] |
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.
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.
No description provided.