tutorial3 set



In [4]:
shapes = ['circle','square','triangle','circle']

In [5]:
setOfShapes = set(shapes)

In [6]:
setOfShapes


Out[6]:
set(['circle', 'square', 'triangle'])

In [7]:
setOfShapes.add('polygon')

In [8]:
setOfShapes


Out[8]:
set(['circle', 'square', 'triangle', 'polygon'])

In [9]:
'circle' in setOfShapes


Out[9]:
True

In [12]:
'rhombus' in setOfShapes


Out[12]:
False

In [13]:
favoriteShapes = ['circle','triangle','hexagon']

In [14]:
setOfFavoriteShapes = set(favoriteShapes)

In [15]:
setOfShapes - setOfFavoriteShapes


Out[15]:
set(['square', 'polygon'])

In [16]:
setOfShapes & setOfFavoriteShapes


Out[16]:
set(['circle', 'triangle'])

In [17]:
setOfShapes | setOfFavoriteShapes


Out[17]:
set(['square', 'triangle', 'polygon', 'circle', 'hexagon'])

In [ ]: