-
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
'Solution' #1626
base: master
Are you sure you want to change the base?
'Solution' #1626
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
class Person: | ||
# write your code here | ||
pass | ||
people = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
def __init__(self, name: str, age: int) -> None: | ||
self.name = name | ||
self.age = age | ||
self.people[self.name] = self | ||
|
||
|
||
def create_person_list(people: list) -> list: | ||
# write your code here | ||
pass | ||
our_list = [] | ||
for human in people: | ||
person = Person(human["name"], human["age"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if human.get("husband"): | ||
person.husband = human["husband"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of directly assigning |
||
if human.get("wife"): | ||
person.wife = human["wife"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, consider optimizing the assignment of |
||
our_list.append(person) | ||
|
||
for item in our_list: | ||
if hasattr(item, "wife"): | ||
for i in our_list: | ||
if i.name == item.wife: | ||
item.wife = i | ||
|
||
if hasattr(item, "husband"): | ||
for i in our_list: | ||
if i.name == item.husband: | ||
item.husband = i | ||
|
||
return our_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.
The
people
dictionary is correctly defined as a class attribute, but ensure that it is used consistently throughout the class to store instances by their name as required by the task description.