Skip to content

Commit

Permalink
fix dangling keyfunc examples in documentation of heapq and sorted (G…
Browse files Browse the repository at this point in the history
…H-1432)

* fix dangling mention of key=str.lower in heapq doc

* Fix dangling mention of keyfunc example for sorted()
(cherry picked from commit 6bdb6f7)

Co-authored-by: Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
  • Loading branch information
2 people authored and briancurtin committed Oct 15, 2018
1 parent 1370832 commit c804a59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,8 @@ are always available. They are listed here in alphabetical order.
Has two optional arguments which must be specified as keyword arguments.

*key* specifies a function of one argument that is used to extract a comparison
key from each list element: ``key=str.lower``. The default value is ``None``
(compare the elements directly).
key from each element in *iterable* (for example, ``key=str.lower``). The
default value is ``None`` (compare the elements directly).

*reverse* is a boolean value. If set to ``True``, then the list elements are
sorted as if each comparison were reversed.
Expand Down
10 changes: 5 additions & 5 deletions Doc/library/heapq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ The module also offers three general purpose functions based on heaps.

Return a list with the *n* largest elements from the dataset defined by
*iterable*. *key*, if provided, specifies a function of one argument that is
used to extract a comparison key from each element in the iterable:
``key=str.lower`` Equivalent to: ``sorted(iterable, key=key,
reverse=True)[:n]``
used to extract a comparison key from each element in *iterable* (for example,
``key=str.lower``). Equivalent to: ``sorted(iterable, key=key,
reverse=True)[:n]``.


.. function:: nsmallest(n, iterable, key=None)

Return a list with the *n* smallest elements from the dataset defined by
*iterable*. *key*, if provided, specifies a function of one argument that is
used to extract a comparison key from each element in the iterable:
``key=str.lower`` Equivalent to: ``sorted(iterable, key=key)[:n]``
used to extract a comparison key from each element in *iterable* (for example,
``key=str.lower``). Equivalent to: ``sorted(iterable, key=key)[:n]``.


The latter two functions perform best for smaller values of *n*. For larger
Expand Down

0 comments on commit c804a59

Please sign in to comment.