-
Notifications
You must be signed in to change notification settings - Fork 0
/
join sets.py
48 lines (42 loc) · 905 Bytes
/
join sets.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
#union
set1 = {"a", "b", "c"}
set2 = {1, 2, 3}
set3 = set1.union(set2)
print(set3)
print()
#update
set1 = {"a", "b", "c"}
set2 = {1, 2, 3}
set1.update(set2)
print(set1)
print()
#keep only duplicates
set1 = {"a", "b", "c", 1}
set2 = {1, 2, 3, 4}
set1.intersection_update(set2)
print(set1)
print()
#duplicate alone to new set
set1 = {"a", "b", "c", 1}
set2 = {1, 2, 3, 4}
set3 = set1.intersection(set2)
print(set3)
print()
#keep all but no duplicates
set1 = {"a", "b", "c", 1}
set2 = {1, 2, 3, 4}
set1.symmetric_difference_update(set2)
print(set1)
print()
#no duplicates to new set
set1 = {"a", "b", "c", 1}
set2 = {1, 2, 3, 4}
set3 = set1.symmetric_difference(set2)
print(set3)
print()
#True and 1 are considered same
set1 = {"a", "b", "c", True, False}
set2 = {1, 2, 3, 4, 5, "google", "mine"}
set3 = set1.symmetric_difference(set2)
print(set3)
print()