]> granicus.if.org Git - python/commitdiff
#22237: document that sorted() is guaranteed to be stable. Initial patch by Martin...
authorEzio Melotti <ezio.melotti@gmail.com>
Tue, 28 Oct 2014 11:57:11 +0000 (12:57 +0100)
committerEzio Melotti <ezio.melotti@gmail.com>
Tue, 28 Oct 2014 11:57:11 +0000 (12:57 +0100)
Doc/library/functions.rst
Doc/library/heapq.rst
Misc/ACKS

index c4d1eaa40b115ab1e43b72886630a95064cdcbeb..d8a3dcfb3ebcf7bf44d89930ebd46e1a63c57ea0 100644 (file)
@@ -1318,6 +1318,11 @@ available.  They are listed here in alphabetical order.
    each element only once.  Use :func:`functools.cmp_to_key` to convert an
    old-style *cmp* function to a *key* function.
 
+   The built-in :func:`sorted` function is guaranteed to be stable. A sort is
+   stable if it guarantees not to change the relative order of elements that
+   compare equal --- this is helpful for sorting in multiple passes (for
+   example, sort by department, then by salary grade).
+
    For sorting examples and a brief sorting tutorial, see `Sorting HowTo
    <http://wiki.python.org/moin/HowTo/Sorting/>`_\.
 
index e8acd6c2e0aeb2e14cfe0847ac2195a5bb0232d5..617e3fe630e4abd7923584216684f107138dbc15 100644 (file)
@@ -136,7 +136,6 @@ pushing all values onto a heap and then popping off the smallest values one at a
 time::
 
    >>> def heapsort(iterable):
-   ...     'Equivalent to sorted(iterable)'
    ...     h = []
    ...     for value in iterable:
    ...         heappush(h, value)
@@ -145,6 +144,9 @@ time::
    >>> heapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
+This is similar to ``sorted(iterable)``, but unlike :func:`sorted`, this
+implementation is not stable.
+
 Heap elements can be tuples.  This is useful for assigning comparison values
 (such as task priorities) alongside the main record being tracked::
 
index fad0d8856be072619b32901d602a5bde4a531e60..cf1cd619b16ba8f880eea0d748b900589b984d2e 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1008,6 +1008,7 @@ Todd R. Palmer
 Juan David Ibáñez Palomar
 Jan Palus
 Yongzhi Pan
+Martin Panter
 Mathias Panzenböck
 M. Papillon
 Peter Parente