Skip to content

Updating a code example in the docs - classes.rst - #27341

Closed
sameh-farouk wants to merge 2 commits into
python:mainfrom
sameh-farouk:patch-1
Closed

sameh-farouk wants to merge 2 commits into
python:mainfrom
sameh-farouk:patch-1

Conversation

@sameh-farouk

Copy link
Copy Markdown

the giving example for the generator expressions that yield all words from a page will actually yield all the characters from that page instead, giving that the page holds a multiline string as the name implies.

>>> page = """hello, world
... I love Python!"""
>>> set(word for line in page for word in line.split())
{'n', 'h', 'd', 'o', 'e', ',', 'r', 'I', 't', 'v', 'P', 'l', 'w', 'y', '!'}

the example could be correct only if the page variable contains a list for lines instead, but then the variable name would need to reconsider, for example, lines.

the correct code would be something like:

>>> set(word for line in page.splitlines() for word in line.split())
{'love', 'world', 'I', 'hello,', 'Python!'}

the same generator expressions also could be simplified to just

>>> set(word for word in page.split())
{'love', 'world', 'I', 'hello,', 'Python!'}

the giving example for the generator expressions that yield all words from a page will actually yield all the characters from that page instead, giving that the `page` holds a multiline string.
the example could be correct only if the `page` variable contains a list for lines instead, but then the variable name would need to reconsider, ex: `lines`.

also the same generator expressions could be simplified to just `unique_words = set(word for word in page.split())`
@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@sameh-farouk

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Jul 24, 2021
Comment thread Doc/tutorial/classes.rst Outdated
Co-authored-by: Dominic Davis-Foster <dominic@davis-foster.co.uk>
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 28, 2021
@github-actions

Copy link
Copy Markdown

Closing this stale PR because the CLA is still not signed.

@github-actions github-actions Bot closed this Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants