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
Bad example in set tutorial #48820
Comments
On http://docs.python.org/3.0/tutorial/datastructures.html#sets there is >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>> print(basket)
{'orange', 'bananna', 'pear', 'apple'}
>>> fruit = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> fruit = set(basket) # create a set without duplicates
>>> fruit
{'orange', 'pear', 'apple', 'banana'} The third command should be an assignment to basket rather than fruit. |
Also, I see banana is misspelled on the first output line (line 3). |
Fixed r67624. |
I see that the spelling of banana has been fixed but what is the purpose of assigning fruit and then immediately reassigning it another value without even looking at the first assignment?
|
Confirmed in trunk and 3.1 |
Replaced unused variable assignment with a call to set() for illustrative purposes. |
You may want to add another space before the comment, otherwise it will be the only one not aligned with the others. |
I guess giving fruit, the set of unique fruit a different name makes it more clear. Comments alignment fixed. >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>> print(basket)
{'orange', 'bananna', 'pear', 'apple'}
>>> fruit = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> uniquefruit = set(fruit) # create a set without duplicates
>>> uniquefruit
{'orange', 'pear', 'apple', 'banana'} |
I think this change fits well with the rest of the example without having to rework things. Spacing fixed. |
I'll get to this soon. |
Fixed in r83809 and r83810. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: