-
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
'help' #1625
base: master
Are you sure you want to change the base?
'help' #1625
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,35 @@ | ||
class Person: | ||
# write your code here | ||
pass | ||
people = {} | ||
|
||
def __init__(self, name: str, age: int) -> None: | ||
self.name = name | ||
self.age = age | ||
self.husband = None | ||
self.wife = None | ||
Person.people[name] = self | ||
|
||
def set_relationships(self, people: dict) -> dict: | ||
if "wife" in people and people["wife"]: | ||
self.wife = Person.people[people["wife"]] | ||
elif "wife" in people: | ||
if hasattr(self, "wife"): | ||
del self.wife | ||
|
||
if "husband" in people and people["husband"]: | ||
self.husband = Person.people[people["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. Similar to the wife's check, ensure that the husband's name exists in |
||
elif "husband" in people: | ||
if hasattr(self, "husband"): | ||
del self.husband | ||
|
||
|
||
def create_person_list(people: list) -> list: | ||
# write your code here | ||
pass | ||
person_objects = [] | ||
for person_data in people: | ||
person = Person(person_data["name"], person_data["age"]) | ||
person_objects.append(person) | ||
|
||
for person_data in people: | ||
person = Person.people[person_data["name"]] | ||
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. Ensure that the person's name exists in |
||
person.set_relationships(person_data) | ||
|
||
return person_objects |
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 code assumes that the wife's name exists in
Person.people
. Consider adding a check to ensure the name exists before accessing it to avoid potentialKeyError
.