I have a list of strings that I would like to find in the phrase. Then delete the list if the combination does not exist. Is there a python list understanding that will work?
word_list = ["Dogs love ice cream", "Cats love balls", "Ice cream", "ice cream is good with pizza", "cats hate ice cream"] keep_words = ["Dogs", "Cats"] Delete_word = ["ice cream"]
Remove the words that contain ice cream, but if dogs or cats are in the sentence, keep it.
Desired_output = ["Dogs love ice cream", "Cats love balls", "cats hate ice cream"]
I tried this code and tried to use AND and OR, but could not get the combination correctly.
output_list = [x for x in word_list if "ice cream" not in x]
source share