-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 27102023 #829
base: master
Are you sure you want to change the base?
Solution 27102023 #829
Changes from 1 commit
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,27 @@ | ||||||||||||||||||||
class Person: | ||||||||||||||||||||
# write your code here | ||||||||||||||||||||
pass | ||||||||||||||||||||
|
||||||||||||||||||||
people = {} | ||||||||||||||||||||
|
||||||||||||||||||||
def create_person_list(people: list) -> list: | ||||||||||||||||||||
# write your code here | ||||||||||||||||||||
pass | ||||||||||||||||||||
def __init__(self, name: str, age: int) -> None: | ||||||||||||||||||||
self.name = name | ||||||||||||||||||||
self.age = age | ||||||||||||||||||||
Person.people.update({self.name: self}) | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def create_person_list(people1: list) -> list: | ||||||||||||||||||||
output_list = [] | ||||||||||||||||||||
for pers in people1: | ||||||||||||||||||||
pers_inst = Person(pers["name"], pers["age"]) | ||||||||||||||||||||
if "wife" in pers and pers["wife"] is not None: | ||||||||||||||||||||
pers_inst.wife = pers["wife"] | ||||||||||||||||||||
elif "husband" in pers and pers["husband"] is not None: | ||||||||||||||||||||
pers_inst.husband = pers["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.
Suggested change
|
||||||||||||||||||||
for pers1 in Person.people: | ||||||||||||||||||||
if hasattr(Person.people[pers1], "wife"): | ||||||||||||||||||||
Person.people[pers1].wife =\ | ||||||||||||||||||||
Person.people[Person.people[pers1].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. Use |
||||||||||||||||||||
if hasattr(Person.people[pers1], "husband"): | ||||||||||||||||||||
Person.people[pers1].husband =\ | ||||||||||||||||||||
Person.people[Person.people[pers1].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. Use |
||||||||||||||||||||
output_list.append(Person.people[pers1]) | ||||||||||||||||||||
return output_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.
Firstly, you need just create all instances of Person without assign a husband and a wife. You can add the created instances to output_list. And the last, you can use a list comprehension instead of the loop.
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.
Still not fixed