<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Sets
A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Creating Sets
Step1:  Set can contain only unique entries. If you try to duplicate an entry in the set
Step2:  Sets will not allow any mutable objects. As you can see tuples are accepted as elements in a set while list is not which is a mutable object.
Step3:  Mutable and Immutable Sets
Although some of the mutable elements (like list) are not allowed in set, set itself is mutable.
Step4:  Set Operations
Add, Remove Elements
<ASSISTANT_TASK:>
Python Code:
set1 = set('Moment of Truth')
set1
set2 = set()
set2.add('A')
set2
# set is similar to dictionary but containing only keys
setA = {'Apple','America','August'}
setA
Explanation: Sets
A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Creating Sets
End of explanation
set3 = set()
set3.add('Blue')
set3.add('Green')
print(set3)
set3.add('Blue')
print(set3)
# please note set is case-sensitive
colors = ['Blue','Green','Red','White','blue','Blue','White','Black']
unique_colors = set(colors)
print(unique_colors)
Explanation: Set can contain only unique entries. If you try to duplicate an entry in the set
End of explanation
set4 = {'A',('B','C')}
set4
set5 = {'X',['Y','Z']} # will generate error
set5
Explanation: Sets will not allow any mutable objects. As you can see tuples are accepted as elements in a set while list is not which is a mutable object.
End of explanation
# Mutable Set
set6 = set(['A','B','C','D','E'])
set6.add('F')
print(set6)
# Immutable Set
set7 = frozenset(['A','B','C'])
set7.add('D') # will generate error
set7
# Sets are unordered, to get ordered set use sorted function
set8 = sorted(set6)
set8
Explanation: Mutable and Immutable Sets
Although some of the mutable elements (like list) are not allowed in set, set itself is mutable.
End of explanation
set6.clear()
set6
print(set4)
set4.remove('A') # will report an error if element is not present
print(set4)
set4.discard('A') # will not report an error if element is not present
print(set4)
set4.remove('A') # this will create an error
print(len(set4))
set4.add('A')
set4.add(('D','E'))
print(set4)
# add will not take any mutable object like list
set4.add(['1','2'])
set4 # this will create an error
# Union Operator
colorsA = {'Blue','Black','White','Red','Green'}
colorsB = {'Blue','White'}
colorsA.union(colorsB)
# Intersection operator
colorsA.intersection(colorsB)
x = {"a","b","c","d","e"}
x.pop()
x.pop()
# Difference between sets
x = {"a","b","c","d","e"}
y = {"b","c"}
z = {"c","d"}
x.difference(y)
x.difference(y).difference(z)
# instead of using the method difference, we can use the operator "-"
print(x - y)
print(x - y - z)
# difference_update removes all elements of another set from this set. 
x = {"a","b","c","d","e"}
y = {"b","c"}
x.difference_update(y)
print(x)
# x.difference_update(y) is the same as "x = x - y"
x = {"a","b","c","d","e"}
y = {"b","c"}
x = x - y
print(x)
Explanation: Set Operations
Add, Remove Elements
End of explanation
<END_TASK>