I'm trying to build a bad words filter in python (I accept non-coded answers, just need to know more about an algorithm that would work) and I need to know how I can check if a string, contains a specific word in any variation.
For example, let's say my bad word array is:
['others','hello','banana']
And the String I need to check is:
Thinking alike or understanding something in a similar way with others.
For now, I'm looping on the string by checking every time if any element of the array exists in the phrase, but what if I want to check variations of the array? Like 0th3rs
,Oth3r5
for the first element? For now, I'm manually checking it by doing multiple if statements and replacing a
with @
etc... But this would not be good for a production code since I cannot prevent every scenario of character replacing, So I thought of something like an array of objects, where the index is the letter, like A which contains an array of its variations and check it dynamically in the string, but would this take too much time? Since it needs to check every type of word variation? Or is this achievable and usable in a real scenario?