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.
\"or\"
E.g.
You can use a regular expression for this:
import re def contains_word(text, word): return bool(re.search(r'\b' + re.escape(word) + r'\b', text)) print(contains_word('or', 'or')) # True print(contains_word('for', 'or')) # False print(contains_word('to be or not to be', 'or')) # True