Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Solution #856

wants to merge 3 commits into from

Conversation

Grotski
Copy link

@Grotski Grotski commented Nov 19, 2023

No description provided.

app/main.py Outdated
Comment on lines 12 to 26
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)

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:

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
Comment on lines 11 to 14
person_instances = []
for person in people:
person_list = Person(person["name"], person["age"])
person_instances.append(person_list)

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
Comment on lines 17 to 28
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

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

Suggested change
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"]]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooh myyy
ty!!

@Grotski Grotski requested a review from EdAlekseiev November 21, 2023 02:30
Copy link

@EdAlekseiev EdAlekseiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job

Comment on lines +11 to +12
p_inst = []
[p_inst.append(Person(person["name"], person["age"])) for person in people]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants