strange behavior of the comparison operator
Ignacio Vazquez-Abrams
ignacio at openservices.net
Wed Aug 29 14:08:22 EDT 2001
On Wed, 29 Aug 2001, Grant Edwards wrote:
> The only problem I see is that the case where self.r==other.r and self.i >
> other.i isn't handled. That wouldn't cause the problem you've observed, but
> I'd do something like:
>
> def __comp__(self, other):
> if self.r < other.r:
> return -1
> elif self.r > other.r:
> return 1
> else:
> if self.i < other.i:
> return -1
> elif self.i > other.i:
> return 1
> else:
> return 0
Mmm, no. You see, what if you have values like (5+1j) and (2+58j)? are you
sure you want to believe that (5+1j) is larger? It will seem that way if you
use the comparison function above.
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
More information about the Python-list
mailing list