Let\'s say that I am looking for the word \"or\"
. What I want is to check whether that word appears as a word or as a substring of another word.
E.g.
<
You can use the nltk (Natural Language Toolkit) to split the sentence into words, and then check if some word exists with ==
.
NLTK Installation
NLTK Package Download
import nltk
def checkword(sentence):
words = nltk.word_tokenize(sentence)
return any((True for word in words if word == "or"))
print(checkword("Should be false for."))
print(checkword("Should be true or."))