You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Doc/howto/sorting.rst
+22-76Lines changed: 22 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -186,8 +186,8 @@ The `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ algorithm used in Python
186
186
does multiple sorts efficiently because it can take advantage of any ordering
187
187
already present in a dataset.
188
188
189
-
The Old Way Using Decorate-Sort-Undecorate
190
-
==========================================
189
+
Decorate-Sort-Undecorate
190
+
========================
191
191
192
192
This idiom is called Decorate-Sort-Undecorate after its three steps:
193
193
@@ -226,90 +226,36 @@ after Randal L. Schwartz, who popularized it among Perl programmers.
226
226
227
227
Now that Python sorting provides key-functions, this technique is not often needed.
228
228
229
+
Comparison Functions
230
+
====================
229
231
230
-
The Old Way Using the *cmp* Parameter
231
-
=====================================
232
-
233
-
Many constructs given in this HOWTO assume Python 2.4 or later. Before that,
234
-
there was no :func:`sorted` builtin and :meth:`list.sort` took no keyword
235
-
arguments. Instead, all of the Py2.x versions supported a *cmp* parameter to
236
-
handle user specified comparison functions.
237
-
238
-
In Py3.0, the *cmp* parameter was removed entirely (as part of a larger effort to
239
-
simplify and unify the language, eliminating the conflict between rich
240
-
comparisons and the :meth:`__cmp__` magic method).
241
-
242
-
In Py2.x, sort allowed an optional function which can be called for doing the
243
-
comparisons. That function should take two arguments to be compared and then
244
-
return a negative value for less-than, return zero if they are equal, or return
245
-
a positive value for greater-than. For example, we can do:
0 commit comments