[Python-3000] None in Comparisons

Bruce Leban bruce at leapyear.org
Wed Nov 12 20:52:41 CET 2008


On Tue, Nov 11, 2008 at 2:00 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> M.-A. Lemburg wrote:
>
>> On 2008-11-11 14:28, Antoine Pitrou wrote:
>>
>>  But why should "n/a" (or "missing", or "undefined") imply "smaller than
>>> everything else"?
>>>
>>
>> It's just a convention based on viewing None as "nothing" or the
>> empty set.
>>
>
> It would be possible to implement this convention in the
> sort method, without making it a feature of comparisons
> in general.
>

+1

None / Missing / undefined should be able to be sorted with other data. If
this requires adding an optional parameter to sort, I'm fine with that. Note
that this works with strings today:

x = "abc"
y = "abcd"
x < y

note that x[3] is undefined and the comparison operator (and sorting)
automatically places x before y when all other elements of x and y are
equal. Likewise if I created a comparison method for a class I would
probably order

C(a=1) < C(a=2) < C(a=2, b=3)

I understand why you don't want to make None comparison work generally for
the < operator.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20081112/1423e814/attachment.htm>


More information about the Python-3000 mailing list