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

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -