Given a string paragraph and a string word, determine whether word appears in paragraph as a whole word.
An occurrence counts as a whole word when the character on each side of it is a non-letter (a space or punctuation) or the start or end of the string. The comparison is case-insensitive. Return True if at least one whole-word occurrence exists and False otherwise.
Function Signature
def is_word_present(paragraph: str, word: str) -> bool:
Rules
-
Only the English letters
A-Z
and
a-z
count as letters. Every other character, including apostrophes and hyphens, separates words, so "fox" is found in "fox's" and in "fox-like".
-
word
is a single word made only of English letters.
-
An occurrence inside a longer run of letters does not count, so "fox" is not found in "foxes".
Constraints
-
1 <= len(paragraph) <= 1000
-
1 <= len(word) <= 50
-
paragraph
consists of English letters, spaces, and punctuation characters.
-
word
consists of English letters.
Examples
Input: paragraph = "The quick brown fox jumps over the lazy dog.", word = "fox"
Output: True
"fox" sits between two spaces, so it is a whole word.
Input: paragraph = "Hello, world! Hello again.", word = "HELLO"
Output: True
"Hello" at the start of the paragraph is followed by a comma, and it equals "HELLO" once case is ignored.
Input: paragraph = "The foxes outfoxed the hounds.", word = "fox"
Output: False
The letters "fox" appear twice, but both times inside a longer word ("foxes" and "outfoxed"), with a letter right next to them.