Is UserList.py "strange" or is it cmp()?

Alex alex at somewhere.round.here
Tue Mar 14 14:37:49 EST 2000


Hi, Tom.

> >>> ul == aList
> in UserList.__cmp__(self=[0, 1, 2, 3], other=[0, 1, 2, 3]):
>    false leg: cmp(self.data, other)=0
> 1
> >>> cmp(ul,aList)
> in UsreList.__cmp__(self=[0, 1, 2, 3], other=[0, 1, 2, 3]):
>    false leg: cmp(self.data, other)=0
> 0

cmp should actually return 0 when it thinks its arguments are equal.  It
confused me for a while, too, but it makes sense in the context of an
ordering.  Usually, the way it's supposed to work is

cmp (a, b) => -1  if a < b
cmp (a, b) =>  0  if a == b
cmp (a, b) =>  1  if a > b

which is consistent with the results you got.  I guess that 'a == b' is
actually returning (not cmp (a, b))

Alex.



More information about the Python-list mailing list