String comparison question

Peter Otten __peter__ at web.de
Mon Mar 20 07:59:21 EST 2006


luc.saffre at gmail.com 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\nB    C'
> 
> Here is how I do such comparisons:
> 
>   if a.strip().split() == b.strip().split()

The strip() is not necessary:

>>> " a b c\n  ".split() == "a b c".split()
True

Peter



More information about the Python-list mailing list