Why does min(A, B) not raise an error if A, B actually can't be compared?

Raymond Hettinger python at rcn.com
Fri Aug 26 17:38:15 EDT 2005


[Claudio Grondi]
> The still open question for me then is:
> Why does min() not raise an error in case
> there is no comparison function definition
> for the feeded objects available?

Actually, there is a comparison function for
class instances.  Unfortunately, the default
method is not very useful in your case.  It
works a bit like this:

    def __cmp__(self, other):
        return cmp(id(self), id(other))

This is mildly useful as it allows distinct
objects to have an ordering relation.


Raymond




More information about the Python-list mailing list