-
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 #778
base: master
Are you sure you want to change the base?
Solution #778
Conversation
To be honest, I think my implementation of the task is not good. Can someone help to implement this task in a more convenient way? |
Now It may be better) |
app/main.py
Outdated
def __init__(self, name: str, age: int) -> None: | ||
self.name = name | ||
self.age = age | ||
Person.people[name] = self |
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.
Person.people[name] = self | |
self.pople[name] = self |
maybe it will be better
app/main.py
Outdated
for index, person in enumerate(people_data): | ||
wife = person.get("wife") | ||
husband = person.get("husband") | ||
if 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.
Is not None
is redundant here, since in your case if statement will be True if key exists
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.
Got it!
app/main.py
Outdated
husband = person.get("husband") | ||
if wife is not None: | ||
person_list[index].wife = Person.people.get(wife) | ||
if husband 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.
same
app/main.py
Outdated
def create_person_list(people_data: dict) -> list[Person]: | ||
person_list = [] | ||
|
||
for person_item in people_data: |
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.
Try to rewrite in one line. Hint: list comprehension 🤫
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.
GJ 👍
No description provided.