mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.14] gh-133881: add forward reference to list.sort()
in lambda expression tutorial (GH-133910) (#134126)
gh-133881: add forward reference to `list.sort()` in lambda expression tutorial (GH-133910)
(cherry picked from commit c1c9ad1d5a
)
Co-authored-by: Oleg Burnaev <51371645+Shepard2154@users.noreply.github.com>
This commit is contained in:
parent
d7230e1110
commit
075cabb026
1 changed files with 2 additions and 1 deletions
|
@ -999,7 +999,8 @@ scope::
|
||||||
43
|
43
|
||||||
|
|
||||||
The above example uses a lambda expression to return a function. Another use
|
The above example uses a lambda expression to return a function. Another use
|
||||||
is to pass a small function as an argument::
|
is to pass a small function as an argument. For instance, :meth:`list.sort`
|
||||||
|
takes a sorting key function *key* which can be a lambda function::
|
||||||
|
|
||||||
>>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
|
>>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
|
||||||
>>> pairs.sort(key=lambda pair: pair[1])
|
>>> pairs.sort(key=lambda pair: pair[1])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue