Python 3.0, rich comparisons and sorting order
Alex Martelli
aleaxit at yahoo.com
Wed Sep 22 08:43:50 EDT 2004
Carlos Ribeiro <carribeiro at gmail.com> wrote:
...
> > Python; I argue that pushing such subtle responsibilities down to Python
> > _users_ is no progress.
>
> That pretty much sums my argument very well (Thanks Alex!). I think
You're welcome.
> that sort must simply work. *If* some type of ordering between
I think an acceptable compromise would be for the user to have to do:
import universal_comparator
arbitrary_list.sort(cmp=universal_comparator.cmp)
in order to ensure sort "simply works". Actually, I hope in Python 3K
sort will take just an 'LT', not requiring a full 'CMP' (I believe the
single operator < with the proper semantics is sufficient), but that's a
separate issue. The point is, IMHO, that requiring universal
comparability _is_ rare enough that "comparing anything at all" need not
be the DEFAULT -- but is definitely not rare enough that it can be
simply ignored or pushed down to the users. A universal comparison
function importable from a suitable module seems about right to me.
Alex
More information about the Python-list
mailing list