-
Notifications
You must be signed in to change notification settings - Fork 0
/
31_Sets_joining_methods.py
93 lines (64 loc) · 1.98 KB
/
31_Sets_joining_methods.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Methods in sets
Sets in python more or less work in the same way as sets in mathematics. We can perform operations like union and intersection on the sets just like in mathematics.
1. union()
2. update()
3. intersection()
4. intersection_update()
5. symmetric_difference()
6. symmetric_difference_update()
"""
animes = {"Pokemon", "Doraemon", "Dragon Ball z", "Naruto"}
games = {"COC", "Prince of Persia", "War 3", "Pokemon Leaf Green", "Pokemon"}
"""
1. union()
Add two sets and returns a new set
It returns the new set and does not update the existing set
"""
# print(animes.union(games))
"""
2. update()
Add items into the existing set from the another set
It updates the existing set with the new set
"""
# animes.update(games)
# print(animes)
"""
3. intersection()
intersection() returns items that are similar to both sets
It returns the new set and does not update the existing set
"""
# print(animes.intersection(games))
"""
4. intersection_update()
intersection_update() returns items that are similar to both sets
It updates the existing set and returns None
"""
# animes.intersection_update(games)
# print(animes)
"""
5. symmetric_difference()
symmetric_difference() returns items that are not similar to both sets
It returns the new set and does not update the existing set
"""
# print(animes.symmetric_difference(games))
"""
6. symmetric_difference_update()
symmetric_difference_update() returns items that are not similar to both sets
It updates the existing set and returns None
"""
# animes.symmetric_difference_update(games)
# print(animes)
"""
7. difference()
difference() returns items that are only present in the original set and not in both the sets
It returns the new set and does not update the existing set
"""
# print(animes.difference(games))
"""
8. difference_update()
difference_update() returns items that are only present in the original set and not in both the sets
It updates the existing set and returns None
"""
animes.difference_update(games)
print(animes)