Re: String comparison question

2006-03-22 Thread Fredrik Lundh
Michael Spencer wrote: > a.split() == b.split() is a convenient test, provided you want to normalize > whitespace rather than ignore it. I took the OP's requirements to mean that > 'A B' == 'AB', but this is just a guess. I'm sure someone has studied this in more detail, but intuitively, parti

RE: String comparison question

2006-03-20 Thread Olivier Langlois
Hi Michael, Normalizing the whitespace is what I was looking to do. I guess that that aspect of my original query was not enough clear. But with either solutions, I get the result I wanted. Greetings, Olivier Langlois http://www.quazal.com > -Original Message- > Fredrik Lundh wrote: >

Re: String comparison question

2006-03-20 Thread Michael Spencer
Fredrik Lundh wrote: > " hello world ".split() > ['hello', 'world'] a.split() == b.split() is a convenient test, provided you want to normalize whitespace rather than ignore it. I took the OP's requirements to mean that 'A B' == 'AB', but this is just a guess. Michael -- http://mail.

Re: String comparison question

2006-03-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: >> > I would like to make a string comparison that would return true without >> > regards of the number of spaces and new lines chars between the words >> > >> > like 'A B\nC' = 'A\nBC' > > Here is how I do such comparisons: > > if a.strip().split() == b.strip().spl

Re: String comparison question

2006-03-20 Thread Peter Otten
[EMAIL PROTECTED] wrote: > Michael Spencer wrote: >> Olivier Langlois wrote: >> >> > I would like to make a string comparison that would return true without >> > regards of the number of spaces and new lines chars between the words >> > >> > like 'A B\nC' = 'A\nBC' > > Here is how I do such

Re: String comparison question

2006-03-20 Thread luc . saffre
Michael Spencer wrote: > Olivier Langlois wrote: > > > I would like to make a string comparison that would return true without > > regards of the number of spaces and new lines chars between the words > > > > like 'A B\nC' = 'A\nBC' Here is how I do such comparisons: if a.strip().split()

Re: String comparison question

2006-03-19 Thread Michael Spencer
Alex Martelli wrote: > Michael Spencer <[EMAIL PROTECTED]> wrote: >> >> Here, str.translate deletes the characters in its optional second argument. >> Note that this does not work with unicode strings. > > With unicode, you could do something strictly equivalent, as follows: > > nowhite = dict.f

Re: String comparison question

2006-03-19 Thread Alex Martelli
Michael Spencer <[EMAIL PROTECTED]> wrote: > Olivier Langlois wrote: > > > I would like to make a string comparison that would return true without > > regards of the number of spaces and new lines chars between the words > > > > > like 'A B\nC' = 'A\nBC' > > > > import string > NULL = s

Re: String comparison question

2006-03-19 Thread Alex Martelli
Michael Spencer <[EMAIL PROTECTED]> wrote: > Olivier Langlois wrote: > > 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

Re: String comparison question

2006-03-19 Thread Michael Spencer
Olivier Langlois wrote: > 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? > Simply, that str.translate with two a

RE: String comparison question

2006-03-19 Thread Olivier Langlois
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.m

Re: String comparison question

2006-03-19 Thread Michael Spencer
Olivier Langlois wrote: > I would like to make a string comparison that would return true without > regards of the number of spaces and new lines chars between the words > > like 'A B\nC' = 'A\nBC' > import string NULL = string.maketrans("","") WHITE = string.whitespace def compare(a,b)

String comparison question

2006-03-19 Thread Olivier Langlois
Hi,   I would like to make a string comparison that would return true without regards of the number of spaces and new lines chars between the words   like ‘A   B\nC’ = ‘A\nB    C’   What would be the easiest way to do it in Python?   Thanks, Olivier Langlois http://www.quazal.com