-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42_Loop_&_Join_Sets.py
More file actions
58 lines (44 loc) · 1.1 KB
/
42_Loop_&_Join_Sets.py
File metadata and controls
58 lines (44 loc) · 1.1 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
48
49
50
51
52
53
54
55
56
57
58
# Python - Loop Sets
print("Python - Loop Sets:")
# Loop items
print("\nLoop items:")
set1 = {'apple', 'banana', 'mango'}
for x in set1:
print(x)
# Python - Join Sets
print("\nPython - Join Sets:")
# Join two sets
print("\nJoin two sets:")
print("Example 1:")
set2 = {1, 4, 5, 7, 8}
set3 = {2, 3, 6, 9}
set4 = set2.union(set3)
# print(set2)
print(set4)
print("Example 2:")
set5 = {'toyota', 'nissan'}
set6 = {'volvo', 'mazda'}
set5.update(set6)
print(set5)
# Keeping only the same value
print("\nKeeping only the same value:")
set7 = {'google', 'facebook', 'apple'}
set8 = {'apple', 'banana', 'date'}
set7.intersection_update(set8)
print(set7)
# set7.intersection(set8)
# print(set7)
# Keeping all except the duplicates
print("\nKeeping all except the duplicates:")
set9 = {'apple', 'mango', 'orange'}
set10 = {'apple', 'google', 'amazon'}
set9.symmetric_difference_update(set10)
print(set9)
set11 = set9.symmetric_difference(set10)
print(set11)
# True and 1 is same
print("\nTrue and 1 is same:")
x = {"apple", "banana", "cherry", True}
y = {"google", 1, "apple", 2}
z = x.symmetric_difference(y)
print(z)