6  Sets

Sets are created using curly brackets.

x = {"mango", "banana", "tangerine", "mango", 
     "sugar", "banana", "ackee", "cocoa bean"}
x
{'ackee', 'banana', 'cocoa bean', 'mango', 'sugar', 'tangerine'}
type(x)
set

Note how the set contains unique values only

z = {"strawberry", "acai", "mango", "acai", "banana"}

6.1 Set intersection

x & z
{'banana', 'mango'}

6.2 Set union

x | z
{'acai',
 'ackee',
 'banana',
 'cocoa bean',
 'mango',
 'strawberry',
 'sugar',
 'tangerine'}

6.3 Set difference

x - z
{'ackee', 'cocoa bean', 'sugar', 'tangerine'}

6.4 Symmetric difference

x ^ z
{'acai', 'ackee', 'cocoa bean', 'strawberry', 'sugar', 'tangerine'}

6.5 Check if element in set

'mango' in x
True

6.6 Check subset or superset with >= and <=

x >= z
False