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 #807

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
class Person:
# write your code here
pass

people = {}

def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
Person.people[self.name] = self


def create_person_list(people: list) -> list:
# write your code here
pass
person_list = []

_ = [Person(dc["name"], dc["age"]) for dc in people]

Choose a reason for hiding this comment

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

Suggested change
person_list = []
_ = [Person(dc["name"], dc["age"]) for dc in people]
person_list = [Person(dc["name"], dc["age"]) for dc in people]

Copy link
Author

Choose a reason for hiding this comment

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

when i try this way in the end of test person_list has 2 copies for each Person

Choose a reason for hiding this comment

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

If you delete person_list.append(Person.people[dc["name"]]) in 25 line, you will not have duplicates in person_list


for dc in people:

if dc.get("wife"):
Person.people[dc["name"]].wife = Person.people[dc["wife"]]

if dc.get("husband"):
Person.people[dc["name"]].husband = (
Person.people)[dc["husband"]]

person_list.append(Person.people[dc["name"]])

return person_list
Loading