I need to check whether a string contains any element of a list. I'm currently using this method:
engWords = ["the", "a", "and", "of", "be", "that", "have", "it", "for", "not"]
engSentence = "the dogs fur is black and white"
print("the english sentence is: " + engSentence)
engWords2 = []
isEnglish = 0
for w in engWords:
if w in engSentence:
isEnglish = 1
engWords2.append(w)
if isEnglish == 1:
print("The sentence is english and contains the words: ")
print(engWords2)
The problem with this is that it gives the output:
the english sentence is: the dogs fur is black and white
The sentence is english and contains the words:
['the', 'a', 'and', 'it']
>>>
As you can see 'a' and 'it' should not be present. How can i search so that it will only list individual words, rather than parts of a word also? I'm open to any ideas using normal python code, or regex(although I'm very new to both python and regex, so please nothing too complicated) Thank you.
remodule if you were using them.