String comparison question
olanglois at quazal.com
Mon Mar 20 02:42:47 CET 2006
Your suggestion is fantastic and is doing exactly what I was looking
for! Thank you very much.
There is something that I'm wondering though. Why is the solution you
proposed wouldn't work with Unicode strings?
> import string
> NULL = string.maketrans("","")
> WHITE = string.whitespace
> def compare(a,b):
> """Compare two strings, disregarding whitespace -> bool"""
> return a.translate(NULL, WHITE) == b.translate(NULL, WHITE)
> Here, str.translate deletes the characters in its optional second
> Note that this does not work with unicode strings.
More information about the Python-list