I have a list of words
wordlist = ['hypothesis' , 'test' , 'results' , 'total']
I have a sentence
sentence = "These tests will benefit in the long run."
I want to check to see if the words in wordlist are in the sentence. I know that you could check to see if they are substrings in the sentence using:
for word in wordlist:
if word in sentence:
print word
However, using substrings, I start to match words that are not in wordlist, for example here test will appear as a substring in sentence even though it is tests that is in the sentence. I could solve my problem by using regular expressions, however, is it possible to implement regular expressions in a way to be formatted with each new word, meaning if I want to see if the word is in the sentence then:
for some_word_goes_in_here in wordlist:
if re.search('.*(some_word_goes_in_here).*', sentence):
print some_word_goes_in_here
so in this case the regular expression would interpret some_word_goes_in_here as the pattern that needs to be searched for and not the value of some_word_goes_in_here. Is there a way to format the input of some_word_goes_in_here so that the regular expression searches for the value of some_word_goes_in_here?