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