]> granicus.if.org Git - python/commitdiff
Docs: Add note regarding "reversed" flag in heapq.merge (#300)
authorAdam Niederer <AdamNiederer@users.noreply.github.com>
Sun, 5 Mar 2017 16:56:05 +0000 (11:56 -0500)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Sun, 5 Mar 2017 16:56:05 +0000 (08:56 -0800)
The docs for `heapq.merge` are a little misleading. Iterables passed
into heapq.merge with the reversed flag enabled must be sorted from
largest to smallest to achieve the desired sorting effect, but the
previous paragraph states that they should be sorted from smallest
to largest.

Doc/library/heapq.rst

index 7e33e7481467faa9176f0a2d5f055464affc8166..e36ca8d7b34b1338eb69c62e6d054cd3bf6e46c8 100644 (file)
@@ -100,7 +100,9 @@ The module also offers three general purpose functions based on heaps.
    ``None`` (compare the elements directly).
 
    *reverse* is a boolean value.  If set to ``True``, then the input elements
-   are merged as if each comparison were reversed.
+   are merged as if each comparison were reversed. To achieve behavior similar
+   to ``sorted(itertools.chain(*iterables), reverse=True)``, all iterables must
+   be sorted from largest to smallest.
 
    .. versionchanged:: 3.5
       Added the optional *key* and *reverse* parameters.