I have two strings. One contains digits the other contains words. I cannot predict which one’s which nor the size of the number.
S1 = "thirteen things that don't make sense"
S2 = "13 Things That Don't Make Sense"
obviously
S1 != S2
what is the best way to test in python that the two strings contain the same information?
You could create a mapping of strings that should be considered equivalent to some other string, and then convert each sentence to remove case differences and replace words using the mapping before comparing, for example:
The difficult part here comes from creating a comprehensive
eq_map, the module that CosmicComputer linked may be useful.You may also want to do something here to remove punctuation, you could accomplish this by adding something like
s = re.sub(r'[^\w\s]+', '', s)toconvert().