Comparison of functions

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sat Jul 30 13:10:50 EDT 2005


Steven D'Aprano wrote:
> On Sat, 30 Jul 2005 15:32:45 +0200, Reinhold Birkenfeld wrote:
> 
>>> Um, I didn't ask to compare complex numbers using comparison operators. I
>>> asked to sort a list. And please don't tell me that that sorting is
>>> implemented with comparison operators. That just means that the
>>> implementation is confusing numeric ordering with sort order.
>> 
>> Sorting is implemented with comparison operators. How should it be otherwise?
> 
> That's a good question, and that's why I'm exploring different comparisons
> in Python, trying to understand what Python already does, and the pros and
> cons thereof, before I suggest anything new.
> 
>> Would you prefer a __sort__ method to specify sort order?
> 
> Well, there are an infinite number of sort orders. Most of them are pretty
> much useless, but even if we limit ourselves to common, useful sort
> orders, there are still a good half dozen or more.

That's why the sort method does have certain keyword arguments with which you can
customize sorting to your liking. But unless the standard sort without arguments
should be disallowed, it has to resort to comparison.

> So at this time, I'd rather not be pinned down to some half-baked
> "solution" before I have even understood the problem.

That's wise.

>> But complex numbers are not greater or littler than others. You can't order them,
>> not on a one-dimensional scale.
> 
> Of course you can order them. You are confusing order with magnitude. The
> two are not identical, although they are similar enough in some contexts
> as to cause confusion.

Well, you can order everything according to some specs, but you can't find a default
sort order for everything. That's where custom comparison functions can help.

Correct me if I'm wrong, but is there a default order for complex number?

Reinhold



More information about the Python-list mailing list