This will only work if each name is unique.
First create two accessor methods in your object class that return age and name.
def get_name(self):
return self.name
def get_age(self):
return self.age
Then, create a method using a for loop that iterates through each object in your list. Call for the object name, compare it to the name you're looking for, and if it matches return the age.
def find_age_of(sought_name):
for obj in obj_list:
if (obj.get_name().lower() == sought_name.lower()): #'.lower' negates case differences
return sought_age = obj.get_age()
Finally, call this method using the name as a parameter:
sought_name = 'dylan'
sought_age = find_age_of(sought_name)