Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reserved word pair used in lambda tutorial without being noted as a reserved word #84821

Closed
ChasBelov mannequin opened this issue May 16, 2020 · 2 comments
Closed

Reserved word pair used in lambda tutorial without being noted as a reserved word #84821

ChasBelov mannequin opened this issue May 16, 2020 · 2 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir

Comments

@ChasBelov
Copy link
Mannequin

ChasBelov mannequin commented May 16, 2020

BPO 40641
Nosy @mdickinson, @ChasBelov

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-05-16.10:05:13.643>
created_at = <Date 2020-05-16.06:57:50.222>
labels = ['3.7', 'invalid', 'docs']
title = 'Reserved word pair used in lambda tutorial without being noted as a reserved word'
updated_at = <Date 2020-05-16.10:05:13.642>
user = 'https://github.com/ChasBelov'

bugs.python.org fields:

activity = <Date 2020-05-16.10:05:13.642>
actor = 'mark.dickinson'
assignee = 'docs@python'
closed = True
closed_date = <Date 2020-05-16.10:05:13.643>
closer = 'mark.dickinson'
components = ['Documentation']
creation = <Date 2020-05-16.06:57:50.222>
creator = 'Chas Belov'
dependencies = []
files = []
hgrepos = []
issue_num = 40641
keywords = []
message_count = 2.0
messages = ['369017', '369020']
nosy_count = 3.0
nosy_names = ['mark.dickinson', 'docs@python', 'Chas Belov']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue40641'
versions = ['Python 3.7']

@ChasBelov
Copy link
Mannequin Author

ChasBelov mannequin commented May 16, 2020

In the tutorial for lambda expressions at https://docs.python.org/3.7/tutorial/controlflow.html#lambda-expressions the reserved word pair is introduced without noting that it is a reserved word. In the example given, I wasn't sure whether pair was a reserved word or whether the interpreter was parsing the plural "pairs" which is presumable an arbitrary name.

Actual content:

The above example uses a lambda expression to return a function. Another use is to pass a small function as an argument:

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

Candidate expected content:

The above example uses a lambda expression to return a function. Another use is to pass a small function as an argument, for example, the reserved word pair to designate the position in a tuple pair:

>>> items = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
>>> items.sort(key=lambda pair: pair[1])
>>> items
[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]

@ChasBelov ChasBelov mannequin added the 3.7 (EOL) end of life label May 16, 2020
@ChasBelov ChasBelov mannequin assigned docspython May 16, 2020
@ChasBelov ChasBelov mannequin added the docs Documentation in the Doc dir label May 16, 2020
@mdickinson
Copy link
Member

pair isn't a reserved word here; it's just the formal parameter name. Think of the lambda here as being equivalent to a function

    def second(pair):
        return pair[1]

You can replace the word "pair" here with any other valid Python identifier, and it'll still work the same way.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant