This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: code example index error in tutorial controlflow
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: HVoltBb, docs@python, eric.smith
Priority: normal Keywords:

Created on 2021-05-20 23:08 by HVoltBb, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg394077 - (view) Author: HVoltBb (HVoltBb) Date: 2021-05-20 23:08
An index error in the code example given just above https://docs.python.org/3/tutorial/controlflow.html#documentation-strings

The code now is :
pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
pairs.sort(key=lambda pair: pair[1])
pairs

The "pair[1]" in the second line should be "pair[0]".
msg394093 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-05-21 01:26
The example is correct. The result is sorted by the second item (index=1) of each tuple:

four
one
three
two

Maybe the text could make it more clear that that's the desired output.
msg394147 - (view) Author: HVoltBb (HVoltBb) Date: 2021-05-21 19:55
right. I just realized that the moment I hit the submit button, and I closed this issue right away. Thanks for clearing it up.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88365
2021-05-21 19:55:23HVoltBbsetmessages: + msg394147
2021-05-21 01:26:55eric.smithsetnosy: + eric.smith
messages: + msg394093
2021-05-20 23:13:13HVoltBbsetstatus: open -> closed
resolution: not a bug
stage: resolved
2021-05-20 23:08:33HVoltBbcreate