Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 476a31e

Browse files
committed
Issue 9802: Document min()/max() sort stability
1 parent 1006bd4 commit 476a31e

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Doc/library/functions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ are always available. They are listed here in alphabetical order.
634634
The optional keyword-only *key* argument specifies a one-argument ordering
635635
function like that used for :meth:`list.sort`.
636636

637+
If multiple items are maximal, the function returns the first one encountered.
638+
This is consistent with other sort-stability preserving tools such as
639+
``sorted(iterable, key=keyfunc, reverse=True)[0]` and
640+
``heapq.nlargest(1, iterable, key=keyfunc)``.
637641

638642
.. function:: memoryview(obj)
639643
:noindex:
@@ -651,6 +655,10 @@ are always available. They are listed here in alphabetical order.
651655
The optional keyword-only *key* argument specifies a one-argument ordering
652656
function like that used for :meth:`list.sort`.
653657

658+
If multiple items are minimal, the function returns the first one encountered.
659+
This is consistent with other sort-stability preserving tools such as
660+
``sorted(iterable, key=keyfunc)[0]` and
661+
``heapq.nsmallest(1, iterable, key=keyfunc)``.
654662

655663
.. function:: next(iterator[, default])
656664

0 commit comments

Comments
 (0)