-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSets.py
67 lines (59 loc) · 1.26 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Q. 26:
#Sets(Control Stmt - for-while)
#Write a program to do basic set operations
#Input:Two Sets
#Output:
#Result of Union,intersection,difference and symmetric difference operations on the given input
#Refer sample input and output for formatting specification.
l1 = int(input())
l2 = int(input())
s1 = []
s2 = []
U = []
I = []
D = []
f = 0
for i in range(l1):
s1.append(int(input()))
for i in range(l2):
s2.append(int(input()))
for i in range(l1):
U.append(s1[i])
for i in range(l2):
U.append(s2[i])
U = list(dict.fromkeys(U))
for i in range(l1):
for j in range(l2):
if s1[i] == s2[j]:
I.append(s1[i])
for i in range(l1):
for j in range(l2):
if s1[i] != s2[j]:
f = 1
else:
f = 0
break
if f == 1:
D.append(s1[i])
print(s1)
print(s2)
print("Union is: {",end = "")
for i in range(len(U)):
if i < len(U)-1:
print(U[i],end = ", ")
else:
print(U[i],end = "}")
print()
print("Intersection is {",end = "")
for i in range(len(I)):
if i < len(I)-1:
print(I[i],end = ", ")
else:
print(I[i],end = "}")
print()
print("Difference is {",end = "")
for i in range(len(D)):
if i < len(D)-1:
print(D[i],end = ", ")
else:
print(D[i],end = "}")