Skip to content

Commit 8271441

Browse files
juhanakristianrhettinger
authored andcommitted
bpo-39374: Updated sorting documentation (GH-18177)
1 parent 4b09dc7 commit 8271441

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Doc/howto/sorting.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ Key Functions
4343
=============
4444

4545
Both :meth:`list.sort` and :func:`sorted` have a *key* parameter to specify a
46-
function to be called on each list element prior to making comparisons.
46+
function (or other callable) to be called on each list element prior to making
47+
comparisons.
4748

4849
For example, here's a case-insensitive string comparison:
4950

5051
>>> sorted("This is a test string from Andrew".split(), key=str.lower)
5152
['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
5253

53-
The value of the *key* parameter should be a function that takes a single argument
54-
and returns a key to use for sorting purposes. This technique is fast because
55-
the key function is called exactly once for each input record.
54+
The value of the *key* parameter should be a function (or other callable) that
55+
takes a single argument and returns a key to use for sorting purposes. This
56+
technique is fast because the key function is called exactly once for each
57+
input record.
5658

5759
A common pattern is to sort complex objects using some of the object's indices
5860
as keys. For example:

0 commit comments

Comments
 (0)