Skip to content

Commit a2779a0

Browse files
committed
Docs: Add note regarding "reversed" flag in heapq.merge
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.
1 parent 53c1892 commit a2779a0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/library/heapq.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ The module also offers three general purpose functions based on heaps.
100100
``None`` (compare the elements directly).
101101

102102
*reverse* is a boolean value. If set to ``True``, then the input elements
103-
are merged as if each comparison were reversed.
103+
are merged as if each comparison were reversed. To achieve behavior similar
104+
to ``sorted(itertools.chain(*iterables), reverse=True)``, all iterables must
105+
be sorted from largest to smallest.
104106

105107
.. versionchanged:: 3.5
106108
Added the optional *key* and *reverse* parameters.

0 commit comments

Comments
 (0)