Solution#2952
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved because it correctly implements all functional requirements: the Person class behaves as expected, Person.people is maintained properly, and create_person_list returns the right instances with the wife/husband relationships wired up correctly. The example relations like person_list[0].wife is person_list[2] and the expected AttributeError for missing spouse attributes will all work with your current logic.
The remaining issues are style-related checklist points rather than functional blockers. In app/main.py, when you build the result list (around the loop over people), you can simplify this by using a list comprehension as recommended, for example: result = [Person(p["name"], p["age"]) for p in people] [CHECKLIST ITEM #3]. Similarly, for spouse lookup, instead of if "wife" in person and person["wife"] is not None:, prefer wife_name = person.get("wife") followed by if wife_name is not None: (and likewise for husband) [CHECKLIST ITEM #4].
Functionally you are in good shape; treating these checklist items as a chance to practice more idiomatic Python will make your code cleaner and more in line with the course guidelines.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| result = [] | ||
| for person in people: | ||
| temp = Person(person["name"], person["age"]) | ||
| result.append(temp) |
There was a problem hiding this comment.
This violates checklist item #3: "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." You currently build result with a for loop; consider a comprehension like [Person(p["name"], p["age"]) for p in people].
| if "wife" in person and person["wife"] is not None: | ||
| temp.wife = Person.people[person["wife"]] | ||
|
|
||
| if "husband" in person and person["husband"] is not None: |
There was a problem hiding this comment.
This violates checklist item #4: "When accessing values in a dictionary, it is better to use the dict.get() method instead of explicitly checking for the presence of a key." Your pattern if "wife" in person and person["wife"] is not None: matches the "Bad example" from the checklist. Use person.get("wife") and person.get("husband") instead.
No description provided.