from re import search, IGNORECASEdef is_string_match(word1, word2): # Case insensitively function that checks if two words are the same # word1: string # word2: string | list # if the word1 is in a list of words if isinstance(word2, list): for word in word2: if search(rf'\b{word1}\b', word, IGNORECASE): return True return False # if the word1 is same as word2 if search(rf'\b{word1}\b', word2, IGNORECASE): return True return False
is_match_word = is_string_match("Hello", "hELLO") True
is_match_word = is_string_match("Hello", ["Bye", "hELLO", "@vagavela"])True
is_match_word = is_string_match("Hello", "Bye")False