File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -1592,6 +1592,15 @@ are always available. They are listed here in alphabetical order.
1592
1592
compare equal --- this is helpful for sorting in multiple passes (for
1593
1593
example, sort by department, then by salary grade).
1594
1594
1595
+ The sort algorithm uses only ``< `` comparisons between items. While
1596
+ defining an :meth: `~object.__lt__ ` method will suffice for sorting,
1597
+ :PEP: `8 ` recommends that all six :ref: `rich comparisons
1598
+ <comparisons>` be implemented. This will help avoid bugs when using
1599
+ the same data with other ordering tools such as :func: `max ` that rely
1600
+ on a different underlying method. Implementing all six comparisons
1601
+ also helps avoid confusion for mixed type comparisons which can call
1602
+ reflected the :meth: `~object.__gt__ ` method.
1603
+
1595
1604
For sorting examples and a brief sorting tutorial, see :ref: `sortinghowto `.
1596
1605
1597
1606
.. decorator :: staticmethod
You can’t perform that action at this time.
0 commit comments