-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetMethods.py
More file actions
47 lines (30 loc) · 1.02 KB
/
setMethods.py
File metadata and controls
47 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Update -> Update the set with the union of this set and others
thisset = {"apple", "banana", "cherry"}
tropical = {"pineapple", "mango", "papaya"}
thisset.update(tropical)
print(thisset)
mylist = ["kiwi", "orange"]
thisset.update(mylist)
print(thisset)
# remove element from the set
thisset.remove("banana")
thisset.discard("orange")
print(thisset)
# Remove a random item by using the pop() method:
thisset.pop()
# Erase all the elements of the set
thisset.clear()
# The del keyword will delete the set completely:
del thisset
# print(thisset)
'''Symmetric Difference Update'''
# Remove the items that are present in both sets, AND insert the items that is not present in both sets:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
# x.symmetric_difference_update(y)
# print(x)
'''Intersection Update'''
# The intersection_update() method removes the items that is not present in both sets (or in all sets if the comparison is done between more than two sets).
x.intersection_update(y)
print(x)
print(y)