I am working with this code:
test_list = ['small_cat', 'big_dog', 'turtle']
if 'dog' not in test_list:
output = 'Good'
else:
output = 'Bad'
print (Output)
Because ‘dog’ is not in the list, ‘output’ will come back with a response of ‘Good’. However, I am looking for ‘output’ to return ‘Bad’ because the word ‘dog’ is part of an item in the list. How would I go about doing this?
>Solution :
You should iterate all the values in test_list –
output = 'Good'
for test_word in test_list:
if 'dog' in test_word:
output = 'Bad'
break
print(output)