[Python-3000] None in Comparisons
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Nov 13 01:54:47 CET 2008
Marcin 'Qrczak' Kowalczyk wrote:
> 2008/11/11 Greg Ewing <greg.ewing at canterbury.ac.nz>:
>
>> It would be possible to implement this convention in the
>> sort method
>
> Until someone wishes to sort a list of some objects by key, where the
> keys can be (1, None) compared with (1, 3).
Yes, I thought of that shortly after posting. Lists and
tuples could be special-cased as well, although someone
is inevitably going to be surprised when their favourite
sequence type doesn't get included in the special
treatment.
However, covering lists and tuples would cover the vast
majority of use cases, I think. So perhaps the best
thing would be to provide this as an option, defaulting
to false, and with the limitations clearly documented.
If someone has a use case not covered by it, they just
have to provide their own key function.
Another approach would be to define a protocol for
comparison-for-sorting, which custom types could implement
if they wanted.
--
Greg
More information about the Python-3000
mailing list