-
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
done #1660
base: master
Are you sure you want to change the base?
done #1660
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.
Great job on implementing the Person
class and the create_person_list
function! 🎉 Your code meets the task requirements and constraints effectively. While there are some suggestions for improvement, such as using dict.get()
for cleaner key checks and considering list comprehension for creating lists, these are minor enhancements. Keep up the good work, and consider these tips for even more readable and efficient code in the future! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
for human in people: | ||
new_people_list.append(Person(human["name"], human["age"])) |
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 new_people_list
. This will make the code more concise and is recommended by the checklist: 'When creating a list of instances from a collection (such as a list of dictionaries), it is recommended to use list comprehension rather than traditional for loops.'
new_people_list.append(Person(human["name"], human["age"])) | ||
|
||
for human in people: | ||
if "wife" in human and human["wife"]: |
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.
Use the dict.get()
method instead of explicitly checking for the presence of a key. This approach simplifies the code and avoids potential KeyError
exceptions, making it cleaner and more concise. For example: if human.get('wife'):
for human in people: | ||
if "wife" in human and human["wife"]: | ||
Person.people[human["name"]].wife = Person.people[human["wife"]] | ||
elif "husband" in human and human["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.
Similarly, use the dict.get()
method here instead of explicitly checking for the presence of a key. For example: elif human.get('husband'):
No description provided.