String comparison question
Olivier Langlois
olanglois at quazal.com
Sun Mar 19 20:42:47 EST 2006
Hi Michael!
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?
Olivier Langlois
http://www.quazal.com
>
> 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
> argument.
> Note that this does not work with unicode strings.
>
> Michael
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list