Say we have the following sentence and words to match
sentences = ['There are three apples and oranges in the fridge.', 'I forgot the milk.']
wordsMatch = ['apples', 'bananas', 'fridge']
How to iterate through the sentences and print them if there is a match without double / triple printing it if it finds more than 1 matches?
For instance, the following code will print the first sentence twice because it finds apples and fridge:
matchedSentences = [sentence for sentence in sentences for word in wordsMatch if word in sentence]
# output: ['There are three apples and oranges in the fridge.', 'There are three apples and oranges in the fridge.']
What solution would be most appropriate?