[Solved] How do I get John’s econ id to be returned? [closed]


Go through every class in data_struct, finding a John, and get its “id”.

Notice “a” John. What if you have more than one? There are a lot of Johns in the world.

So, make sure you’re thinking about what “John” means in your design.

If there are only one of each name, it may be smart to make a dictionary of names to Students, so you can look them up by name.

johns = list(s for students in data_struct.values() for s in students if s.name == "John")

for john in johns:
    print(john.id)

or, for the dictionary version with unique names

student_by_name = dict((student.name, student) for students in data_struct.values() for student in students)

print(student_by_name["John"].id)

2

solved How do I get John’s econ id to be returned? [closed]