We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Advanced Find Matches

Now that we've built the Trie class, we want to provide an advanced word filter for LockedIn to catch variations of bad words efficiently. For example, if the bad word is 'darn', we want to also filter variations like 'd@rn', 'd4rn', or 'd@rn1t'.

Assignment

Complete the advanced_find_matches method. It takes an entire document and a dictionary of character variations as input, and should return a set() of all the words in the trie that exist in the document as continuous substrings, even if the word had a variation character instead of the original.

For example, if:

  • The document contains "d@rn"
  • The variations dictionary contains {'@': 'a'}
  • "darn" is in the trie

...then "d@rn" should be returned as a match.

Tip

The advanced_find_matches method should be very similar to find_matches. Before checking if a character is in the trie, check if that character has a substitution defined in the variations dictionary. If it does, use the substitution character instead of the original.