Create a program that filters out bad words, including obfuscated spellings such as 0 for o and 3 for e.
Asked in the onsite stage. The author used a trie.
Implement filter_bad_words(text, bad_words). Treat contiguous letters and digits as tokens, match case-insensitively after replacing 0 with o and 3 with e, and replace each matching token with asterisks of the same length. Preserve all other characters, including whitespace and punctuation. Matching must apply to whole tokens, so a banned word must not match a longer token.
Input: text is a string and bad_words is a list of lowercase alphabetic strings.
Output: Return the filtered string.
def filter_bad_words(text, bad_words):