0
How do i for example search for pet1 in op?
19 odpowiedzi
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)
+ 1
Not noticed your reply... so late Lenoname
Try this :
for a in op:
print(*a.owner, ',' ,a.pet[0].typeofpet)
0
print(op1 in op)
?? what is p1?
0
Jayakrishna🇮🇳 pet1 sorry
0
Or petlist[0]
0
print(pet1 in op)
print(pet1 in temp)
#simply this way you can search...
0
First do it for single type, on success go for adding other type. Add comments to understand where is problem.. Hope it helps..
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?
0
Where you added temp in op? Am not found.
0
Jayakrishna🇮🇳 Line 76, op1 has [temp[0]],[temp[1]] inside of it
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.
0
Jayakrishna🇮🇳 So i cant search for pet1 in a list of objects?
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.
0
Jayakrishna🇮🇳 I got false even for print(pet1 in op)
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..?
0
Its not really pet1 i’m looking for, its 'hamster', 'pell', 'male', 2
I want go know who owns this pet
0
if pet1 in op1.pet :
print(pet1.typeofpet , "owner is", *op1.owner)
#is this?
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.
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__…….