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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
34 changes: 29 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
class Person:
# write your code here
pass
def __init__(self, name, age):

self.name = name
self.age = age
self.spouse = None

def create_person_list(people: list) -> list:
# write your code here
pass
def __repr__(self):

spouse_info = f", Spouse: {self.spouse.name}" if self.spouse else ""
return f"Person(Name: {self.name}, Age: {self.age}{spouse_info})"


def create_person_list(people_data):
person_dict = {}
for person in people_data:
name = person["name"]
age = person["age"]
person_dict[name] = Person(name, age)

for person in people_data:
name = person["name"]
spouse_name = person.get("wife") or person.get("husband")
if spouse_name:
if spouse_name in person_dict:
person_dict[name].spouse = person_dict[spouse_name]
else:
raise ValueError(
f"Error for '{name}': Spouse name '{spouse_name}' not found in the data."
)

return list(person_dict.values())
Comment on lines +31 to +32

Choose a reason for hiding this comment

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

The return statement is incorrectly indented. It should be outside the for loop to ensure that all entries in people_data are processed before returning the list of Person objects.

Loading