-
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
add update #1656
base: master
Are you sure you want to change the base?
add update #1656
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 submission! Your implementation of the Person
class and the create_person_list
function is mostly correct and meets the task requirements. However, there are a few areas for improvement:
-
Use of
if
Statements: Instead of using explicit checks likeif "wife" in person_data and person_data["wife"]:
, consider using thedict.get()
method for cleaner code. -
Code Style: Enhance your code readability by using list comprehensions instead of traditional
for
loops when creating lists ofPerson
instances. -
Error and Warning Messages: Currently, your code prints error and warning messages directly. It would be beneficial to handle these cases more gracefully, possibly by raising exceptions or logging the messages.
-
Handling Non-Existent Relationships: While your code provides informative warning messages for non-existent relationships, consider implementing additional handling if a husband or wife is not found.
-
Duplicate Person Handling: The check for an existing person with the same name is correct, but it only prints an error message. Consider raising an exception or handling this case more robustly.
These improvements will not only enhance the functionality of your code but also make it more robust and maintainable. Keep up the good work, and continue to refine your coding skills! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
people = {} | ||
|
||
def __init__(self, name: str, age: int) -> None: | ||
if name in Person.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.
The check for an existing person with the same name is correct, but it only prints an error message. Consider raising an exception or handling this case more robustly if needed.
if "wife" in person_data and person_data["wife"]: | ||
wife_name = person_data["wife"] | ||
if wife_name in Person.people: | ||
person.wife = Person.people[wife_name] | ||
else: | ||
print(f"Warning: Wife with name \"{wife_name}\" don't exist") |
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 warning message for a non-existent wife is informative, but consider whether additional handling is needed if the wife is not found.
if "husband" in person_data and person_data["husband"]: | ||
husband_name = person_data["husband"] | ||
if husband_name in Person.people: | ||
person.husband = Person.people[husband_name] | ||
else: | ||
print(f"Husband with name \"{husband_name}\" don't exist") |
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.
Similar to the wife check, the warning message for a non-existent husband is informative, but consider whether additional handling is needed if the husband is not found.
No description provided.