summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2014-10-28 11:57:11 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2014-10-28 11:57:11 (GMT)
commit9f8a5b1abd7ef3fe387daf3ddeb6fe1bc11240b3 (patch)
tree644055ff4e1c6764873c916a88dcbcdbd59cf212 /Doc
parent7876f72f6afe2ac632726770848c444aeb3865cb (diff)
downloadcpython-9f8a5b1abd7ef3fe387daf3ddeb6fe1bc11240b3.zip
cpython-9f8a5b1abd7ef3fe387daf3ddeb6fe1bc11240b3.tar.gz
cpython-9f8a5b1abd7ef3fe387daf3ddeb6fe1bc11240b3.tar.bz2
#22237: document that sorted() is guaranteed to be stable. Initial patch by Martin Panter.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/functions.rst5
-rw-r--r--Doc/library/heapq.rst4
2 files changed, 8 insertions, 1 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index c4d1eaa..d8a3dcf 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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/>`_\.
diff --git a/Doc/library/heapq.rst b/Doc/library/heapq.rst
index e8acd6c..617e3fe 100644
--- a/Doc/library/heapq.rst
+++ b/Doc/library/heapq.rst
@@ -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::