-
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
Develop #1657
base: master
Are you sure you want to change the base?
Develop #1657
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.
Thank you for your hard work on this task! 😊 While your implementation is on the right track, there are a few critical issues that need to be addressed to fully meet the task requirements:
-
Use of List Comprehension: The task recommends using list comprehension to create the list of
Person
instances. This will make your code more concise and efficient. -
Dictionary Access: To prevent potential
KeyError
exceptions, it's important to use thedict.get()
method when accessing dictionary values. This will also simplify your code. -
Handling
wife
/husband
Attributes: The current logic does not correctly handle the absence ofwife
orhusband
keys. Ensure that these attributes are set correctly according to the task requirements. -
Missing Attributes: Make sure to add the
wife
orhusband
attributes to thePerson
instances when these keys are present.
Please address these issues, and feel free to reach out if you need any help! Keep up the great work, and I look forward to seeing your improvements. 🚀
✨ 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) -> list: | ||
# write your code here | ||
pass | ||
person_list = [] |
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 person_list
as recommended in the checklist: person_list = [Person(name=person['name'], age=person['age']) for person in people]
.
app/main.py
Outdated
pass | ||
person_list = [] | ||
|
||
for person in people: |
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 to access dictionary values to avoid potential KeyError
exceptions. For example, person.get('name')
instead of person['name']
.
app/main.py
Outdated
if "wife" in people[i]: | ||
if not people[i]["wife"]: | ||
continue | ||
else: |
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.
Simplify the logic by using if people[i].get('wife'):
instead of checking for the presence of the key and its value separately. This avoids nested if
statements.
app/main.py
Outdated
elif not people[i]["husband"]: | ||
continue | ||
else: |
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, simplify the logic for checking the husband
key by using elif people[i].get('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.
Review Summary
Great job on implementing the create_person_list
function! 🎉 Your code meets the task requirements and constraints, which is a significant achievement. Here are some key points and suggestions for improvement:
-
Class Definition and Initialization: You've correctly defined the
Person
class with the necessary__init__
method, and you're using the class attributepeople
effectively to store instances by theirname
. -
List Comprehension: The use of list comprehension in the
create_person_list
function is well done, creating a list ofPerson
instances from the input list of dictionaries. -
Dictionary Access: Good job using the
dict.get()
method to access thewife
andhusband
keys, which helps prevent potentialKeyError
exceptions. -
Handling
wife
/husband
Attributes: While you have made progress, the logic for setting thewife
andhusband
attributes needs a bit more attention. Ensure that both attributes are set correctly according to the task requirements. This is crucial for the functionality of the code.
Although there are some issues to address, particularly with the handling of wife
and husband
attributes, the decision is to APPROVE this pull request to help you move forward with your learning. Please review the comments and make the necessary improvements to enhance your code. Remember, addressing these issues will help you avoid similar problems in the future. Keep up the great work and continue learning from your experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
pair_name = people[i].get("wife") | ||
if pair_name: | ||
person.wife = get_partner_pointer(pair_name) | ||
elif people[i].get("husband"): | ||
person.husband = get_partner_pointer(people[i].get("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.
The current logic for setting the wife
and husband
attributes is not entirely correct. According to the task requirements, if a person has a wife
, the wife
attribute should be set, and if a person has a husband
, the husband
attribute should be set. The current logic only sets one of these attributes based on the presence of the keys. Consider revising this logic to ensure both attributes are handled correctly.
No description provided.