Message359293
Sorting documentation claims that sorting algorithm is only using < comparisons
https://docs.python.org/3/howto/sorting.html#odd-and-ends
https://docs.python.org/3/library/stdtypes.html#list.sort
When __lt__ implementation is missing, you get an exception
class Foo:
pass
sorted([Foo(), Foo(), Foo()])
TypeError: '<' not supported between instances of 'Foo' and 'Foo'
However, if implement __gt__ method, you doesn't get an exception
class Foo:
def __gt__(self, other):
return False
sorted([Foo(), Foo(), Foo()]) # ok
Is it supposed to work like this? Or is it lack of documentation? |
|
Date |
User |
Action |
Args |
2020-01-04 15:29:55 | yanmitrofanov | set | recipients:
+ yanmitrofanov, docs@python |
2020-01-04 15:29:55 | yanmitrofanov | set | messageid: <1578151795.43.0.682291916428.issue39210@roundup.psfhosted.org> |
2020-01-04 15:29:55 | yanmitrofanov | link | issue39210 messages |
2020-01-04 15:29:55 | yanmitrofanov | create | |
|