14.12.19 15:29, Steven D'Aprano пише:
I might be misinterpreting the evidence, but sorting works on objects
that define `__gt__` without `__lt__`.
py> class A:
... def __init__(self, x): self.x = x
... def __gt__(self, other): return self.x > other.x
...
py> L = [A(9), A(1), A(8)]
py> L.sort()
py> [obj.x for obj in L]
[1, 8, 9]
This class supports '<':
>>> A(1) < A(2)
True
The `<` operator try to use `__lt__`, but if it is not defined falls
back to `__gt__`.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/DJ7L3REYQ23HLXRY425Y4J725WJSTHON/
Code of Conduct: http://python.org/psf/codeofconduct/