0

How do i for example search for pet1 in ownerlist?

https://code.sololearn.com/c1PBlh8mYYRg/?ref=app

28th Mar 2022, 6:45 AM
Lenoname
7 Answers
+ 1
Let me get back to you later, if no other came with an answer by then. I have to go now ...
28th Mar 2022, 8:21 AM
Ipang
0
Can't use <pet1> for searching, it's a variable representing a pet. This can search by name, type or gender def find_pet( owner_list, query_string, category ): result = [] for o in owner_list: for p in o.pets: match = False if category == 1: match = p.name == query_string elif category == 2: match = p.typeofpet == query_string elif category == 3: match = p.gender == query_string if match: result.append( p ) return result pet_name = 'roro' # search by name pet_type = 'cat' # search by type pet_gender = 'male' # search by gender print( f"Find name {pet_name}" ) print( *find_pet( ownerlist, pet_name, 1 ) ) print( f"Find type {pet_type}" ) print( *find_pet( ownerlist, pet_type, 2 ) ) print( f"Find gender {pet_gender}" ) print( *find_pet( ownerlist, pet_gender, 3 ) )
28th Mar 2022, 7:42 AM
Ipang
0
Ipang can i search for petlist[0] in ownerlist instead?
28th Mar 2022, 7:51 AM
Lenoname
0
Yes, first you change find_pet( ) to accept <name>, <type> and <gender> parameters, and make adjustments for qualifying <match>. And then you extract values for those arguments from <petlist[0]> to be used for calling find_pet( ).
28th Mar 2022, 8:03 AM
Ipang
0
Ipang Is that what you did?âŹ†ïž
28th Mar 2022, 8:08 AM
Lenoname
0
What is it exactly are you trying to find? a specific pet, or any pet placed as first element? I think I might have misunderstood you ...
28th Mar 2022, 8:13 AM
Ipang
0
Ipang I’m gonna show the ”user” a list of pets(petlist), he/she is going a to choose a pet based on their position in the list of pets. I then will look for that pet in the ownerlist and see who owns that specific pet
28th Mar 2022, 8:18 AM
Lenoname