Commit afdeca98 authored by Raymond Hettinger's avatar Raymond Hettinger

Issue #4570: Clean-up tutorial example

parent d331ce9e
...@@ -377,16 +377,12 @@ empty dictionary, a data structure that we discuss in the next section. ...@@ -377,16 +377,12 @@ empty dictionary, a data structure that we discuss in the next section.
Here is a brief demonstration:: Here is a brief demonstration::
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] >>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
>>> fruit = set(basket) # create a set without duplicates >>> print(basket) # show that duplicates have been removed
>>> fruit {'orange', 'bananna', 'pear', 'apple'}
{'orange', 'pear', 'apple', 'banana'} >>> 'orange' in basket # fast membership testing
>>> fruit = {'orange', 'apple'} # {} syntax is equivalent to [] for lists
>>> fruit
{'orange', 'apple'}
>>> 'orange' in fruit # fast membership testing
True True
>>> 'crabgrass' in fruit >>> 'crabgrass' in basket
False False
>>> # Demonstrate set operations on unique letters from two words >>> # Demonstrate set operations on unique letters from two words
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment