mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #4570: Clean-up tutorial example
This commit is contained in:
parent
d331ce9e66
commit
afdeca980d
1 changed files with 5 additions and 9 deletions
|
@ -377,16 +377,12 @@ empty dictionary, a data structure that we discuss in the next section.
|
|||
|
||||
Here is a brief demonstration::
|
||||
|
||||
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
|
||||
>>> fruit = set(basket) # create a set without duplicates
|
||||
>>> fruit
|
||||
{'orange', 'pear', 'apple', 'banana'}
|
||||
>>> fruit = {'orange', 'apple'} # {} syntax is equivalent to [] for lists
|
||||
>>> fruit
|
||||
{'orange', 'apple'}
|
||||
>>> 'orange' in fruit # fast membership testing
|
||||
>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
|
||||
>>> print(basket) # show that duplicates have been removed
|
||||
{'orange', 'bananna', 'pear', 'apple'}
|
||||
>>> 'orange' in basket # fast membership testing
|
||||
True
|
||||
>>> 'crabgrass' in fruit
|
||||
>>> 'crabgrass' in basket
|
||||
False
|
||||
|
||||
>>> # Demonstrate set operations on unique letters from two words
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue