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

Solution #1701

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Slava-Nykonenko
Copy link

Class and function are created

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.

Thank you for your hard work on this task! 😊 While your implementation of the Person class and the create_person_list function is mostly correct, there are a few critical issues that need to be addressed to fully meet the task requirements:

  1. Age Parameter Type: The __init__ method of the Person class currently takes age as a string. According to the task description, it should be an integer. This is important for ensuring that the data type aligns with the expected functionality.

  2. Dictionary Access: It's recommended to use the dict.get() method for accessing dictionary values. This approach not only simplifies the code but also prevents potential KeyError exceptions. For example, use person.get('wife') instead of explicitly checking for the presence of a key.

  3. List Comprehension: Consider using list comprehension for creating lists from collections. This will make your code more concise and readable.

Please address these issues to ensure your code meets the core requirements. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀

✨ 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
pass
people = {}

def __init__(self, name: str, age: str) -> None:

Choose a reason for hiding this comment

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

The age parameter in the __init__ method should be an integer, as specified in the task description.

app/main.py Outdated
Comment on lines 12 to 14
for person in people:
name = person["name"]
age = person["age"]

Choose a reason for hiding this comment

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

Consider using person.get('name') and person.get('age') to access dictionary values. This approach avoids potential KeyError exceptions and makes the code cleaner.

app/main.py Outdated
Comment on lines 18 to 23
for person in people:
name = person["name"]
if "wife" in person and person["wife"]:
Person.people[name].wife = Person.people[person["wife"]]
elif "husband" in person and person["husband"]:
Person.people[name].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.

Use dict.get() method instead of explicitly checking for the presence of a key. For example, person.get('wife') instead of "wife" in person and person["wife"].

app/main.py Outdated
Comment on lines 11 to 16
result = []
for person in people:
name = person["name"]
age = person["age"]
instance = Person(name, age)
result.append(instance)

Choose a reason for hiding this comment

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

It is recommended to use list comprehension for creating a list of instances from a collection, as per the checklist.

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.

Review Summary

Great job on improving the implementation of the Person class and the create_person_list function! 🎉 Your code now correctly defines the age parameter as an integer and uses dict.get() for accessing dictionary values, which is a good practice to prevent KeyError exceptions. The use of list comprehension also makes your code more concise and readable.

However, there are a couple of areas to focus on for further improvement:

  1. Dictionary Access: While you've implemented dict.get() for optional keys like 'wife' and 'husband', consider using it for all keys, including 'name', to avoid potential KeyError exceptions if a key is missing.

  2. Code Optimization: The loop that assigns 'wife' and 'husband' could be optimized or combined with the list comprehension to enhance efficiency. Refactoring this part of the code could lead to better performance.

These improvements will enhance the robustness and efficiency of your code. Keep up the great work and continue learning from these experiences! Remember, addressing these issues will help you avoid similar problems in the future. 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

for person_instance in people]

for person_instance in people:
name = person_instance["name"]

Choose a reason for hiding this comment

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

Consider using person_instance.get("name") instead of person_instance["name"] to avoid potential KeyError exceptions if the 'name' key is missing.

Comment on lines +15 to +22
for person_instance in people:
name = person_instance["name"]
if person_instance.get("wife"):
Person.people[name].wife = (
Person.people)[person_instance.get("wife")]
elif person_instance.get("husband"):
Person.people[name].husband = (
Person.people)[person_instance.get("husband")]

Choose a reason for hiding this comment

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

The loop that assigns 'wife' and 'husband' could potentially be optimized or combined with the list comprehension above to improve efficiency. Consider refactoring this part of the code.

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