I have a list of strings:
animals = ["cat meow ", "dog bark"]
And I want to check if each string contains the word "cow" which obviously does not exist in my above list. I am trying to write an if else statement that checks if I am at the end of the list and if cow is not found print "not found ".
The code below prints not found for every element that does not contain the string but I want to print "not found" just once when I iterate my whole list at the end of it but I do not know the correct syntax.
animals = ['dog bark' , 'cat meow ']
for pet in animals:
if 'cow' in pet:
print('found')
else:
print('not found')