How do i for example search for pet1 in op? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i for example search for pet1 in op?

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

28th Mar 2022, 6:46 AM
Lenoname
19 Answers
0
Current you have only one object op1 in op list.. If continue add in same way : you can use a loop like : for obj in op : if pet1 in obj.pet : print(pet1.typeofpet , "owner is", *obj.owner)
28th Mar 2022, 8:12 PM
Jayakrishna 🇮🇳
+ 1
Not noticed your reply... so late Lenoname Try this : for a in op: print(*a.owner, ',' ,a.pet[0].typeofpet)
30th Mar 2022, 9:29 AM
Jayakrishna 🇮🇳
0
print(op1 in op) ?? what is p1?
28th Mar 2022, 9:08 AM
Jayakrishna 🇮🇳
28th Mar 2022, 9:11 AM
Lenoname
0
Or petlist[0]
28th Mar 2022, 9:11 AM
Lenoname
0
print(pet1 in op) print(pet1 in temp) #simply this way you can search...
28th Mar 2022, 9:17 AM
Jayakrishna 🇮🇳
0
First do it for single type, on success go for adding other type. Add comments to understand where is problem.. Hope it helps..
28th Mar 2022, 9:21 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 It turns True for print(pet1 in temp) but False for print(pet1 in op), but temp is included in op so why?
28th Mar 2022, 9:26 AM
Lenoname
0
Where you added temp in op? Am not found.
28th Mar 2022, 9:38 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 Line 76, op1 has [temp[0]],[temp[1]] inside of it
28th Mar 2022, 9:42 AM
Lenoname
0
temp is a list. But op1 is an object. You are adding op1 object to op list. But not added temp list to op. So op don't have temp list.
28th Mar 2022, 9:51 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 So i cant search for pet1 in a list of objects?
28th Mar 2022, 10:18 AM
Lenoname
0
pet1 in list of object pet1 in op returns true because pet1 object is in op list. You can search any valids but if it exists then you get true as result otherwise false.
28th Mar 2022, 10:34 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 I got false even for print(pet1 in op)
28th Mar 2022, 10:44 AM
Lenoname
0
Sry, I mean pet1 is in list of objects petlist list. But op has no object pet1. So pet1 in op return false . pet1 in petlist return true. op has object op1 but op1 is object and temp is a list of objects.. what are want to achieve actually..?
28th Mar 2022, 10:51 AM
Jayakrishna 🇮🇳
0
Its not really pet1 i’m looking for, its 'hamster', 'pell', 'male', 2 I want go know who owns this pet
28th Mar 2022, 10:58 AM
Lenoname
0
if pet1 in op1.pet : print(pet1.typeofpet , "owner is", *op1.owner) #is this?
28th Mar 2022, 11:09 AM
Jayakrishna 🇮🇳
0
This works but op1 is just one person, i want to search through op list because all of the owners will be there not just one.
28th Mar 2022, 11:16 AM
Lenoname
0
Jayakrishna🇮🇳 One more easier question: I want to print out all the contents of op, i tried: for a in op: print(a) Didnt get error but it says [<__main__…….
29th Mar 2022, 3:31 AM
Lenoname