Python compare strings ignore special characters -


i want compare 2 strings such comparison should ignore differences in special characters. is,

hai, test

should match

hai ! test "or" hai test

is there way without modifying original strings?

this removes punctuation , whitespace before doing comparison:

in [32]: import string  in [33]: def compare(s1, s2):     ...:     remove = string.punctuation + string.whitespace     ...:     return s1.translate(none, remove) == s2.translate(none, remove)  in [34]: compare('hai, test', 'hai ! test') out[34]: true 

Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -