-
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 #856
base: master
Are you sure you want to change the base?
Solution #856
Conversation
app/main.py
Outdated
for person in people: | ||
person_list = Person(person["name"], person["age"]) | ||
if "wife" in person and person["wife"] is not None: | ||
wife_name = person["wife"] | ||
if wife_name in Person.people: | ||
person_list.wife = Person.people[wife_name] | ||
Person.people[wife_name].husband = person_list | ||
|
||
elif "husband" in person and person["husband"] is not None: | ||
husband_name = person["husband"] | ||
if husband_name in Person.people: | ||
person_list.husband = Person.people[husband_name] | ||
Person.people[husband_name].wife = person_list | ||
|
||
person_instances.append(person_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.
Better to use two loops. One for creating people instances, second for setting wife/husband
app/main.py
Outdated
person_instances = [] | ||
for person in people: | ||
person_list = Person(person["name"], person["age"]) | ||
if "wife" in person and person["wife"] is not None: |
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.
Instead of and statement use .get
app/main.py
Outdated
person_instances = [] | ||
for person in people: | ||
person_list = Person(person["name"], person["age"]) | ||
person_instances.append(person_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.
Use list comprehension here
app/main.py
Outdated
person_list = Person.people[person["name"]] | ||
right_name = person.get("wife") or person.get("husband") | ||
|
||
if right_name is not None: | ||
if right_name in Person.people: | ||
spouse_instance = Person.people[right_name] | ||
if "wife" in person: | ||
person_list.wife = spouse_instance | ||
spouse_instance.husband = person_list | ||
elif "husband" in person: | ||
person_list.husband = spouse_instance | ||
spouse_instance.wife = person_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.
This code looks difficult to understand, you have to simplify it
person_list = Person.people[person["name"]] | |
right_name = person.get("wife") or person.get("husband") | |
if right_name is not None: | |
if right_name in Person.people: | |
spouse_instance = Person.people[right_name] | |
if "wife" in person: | |
person_list.wife = spouse_instance | |
spouse_instance.husband = person_list | |
elif "husband" in person: | |
person_list.husband = spouse_instance | |
spouse_instance.wife = person_list | |
person_list = Person.people[person["name"]] | |
if person_list.get("wife"): | |
person_list.wife = Person.people[person["wife"]] | |
if person_list.get("husband"): | |
person_list. husband = Person.people[person["husband"]] |
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.
oooh myyy
ty!!
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.
Good job
p_inst = [] | ||
[p_inst.append(Person(person["name"], person["age"])) for person in people] |
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.
p_inst = [] | |
[p_inst.append(Person(person["name"], person["age"])) for person in people] | |
p_inst = [Person(person["name"], person["age"]) for person in people] |
No description provided.