Set 集合
如何分辨dictionary and set?
mySet = set()
print(mySet)
#set()
mySet = set({1,2,3}) #已經有元素的狀況
print(mySet)
#{1, 2, 3}
#change List to Set
myList = [1,4,3,2,5,1,5]
mySet = set(myList)
print(mySet)
#{1, 2, 3, 4, 5}
#no duplicate result now
s = set()
s.add(1)
print(s)
#{1}
s.add(2)
s.add(2)
print(s)
#{1, 2}
#再多加一行add(2) 結果不會有差別
s.add(2)
s.add(3)
s.discard(1)
s.clear()
print(s)
difference() : The returned set contains items that exist only in the first set, and not in both sets.
Ref: https://www.w3schools.com/python/ref_set_difference.asp