-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.py
More file actions
80 lines (61 loc) · 2.3 KB
/
set.py
File metadata and controls
80 lines (61 loc) · 2.3 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# s1 = {10, 20, 30}
# print(s1)
# s2 = set([20, 30, 40]) #create a set out of list
# print(s2)
# s3 = {} #this will create an empty disctionary
# print(type(s3))
# s4 = set() #this will create empty set
# print(type(s4))
# print(s4)
# #insetion in set
# s = {10, 20}
# s.add(30)
# print(s)
# s.add(30) #here it will not add 30 as this value already present in the set, and set will not have duplicate value
# print(s)
# s.update([40,50])
# print(s)
# s.update({60, 70}, [80, 90])
# print(s)
# #removal operation on set
# s = {10, 30, 20, 40}
# print(s)
# s.discard(30) #delete 30, if item is not present in set it will not perform any action
# print(s)
# s.remove(20) #raise an error if the item is not in set
# print(s)
# s.clear() #everything will remove from collections you will have empty set
# print(s)
# s.add(50)
# print(s)
# del s #it will delte the object of set
# #print(s)
# s = {10, 20, 30}
# print (len(s))
# print (20 in s)
# print(50 in s)
###############################################################################################
# s1 = {2, 4, 6, 8}
# s2 = {3, 6, 9}
# print(s1 | s2) #union of two set
# setun = s1.union(s2)
# print(setun)
# print (s1 & s2) #intersection of two set
# setin = s1.intersection(s2)
# print(setin)
# print (s1 - s2)
# setdiff = s1.difference(s2)
# print(setdiff)
# print (s1 ^ s2) #symmitric difference element present in both the set but not common
# setsym = s1.symmetric_difference(s2)
# print ( setsym)
###############################################################################################
s1 = {2, 4, 6, 8}
s2 = {4, 8}
print(s1.isdisjoint(s2)) #boolean value -> true if no common element in set --> false if there is a common element
print(s1 <= s2) #issubset operator s1 is subset of s2 or not
print(s1.issubset(s2))
print(s1 < s2) #if s1 is proper set of s2 or not IF true the s1 should have less element and all the elementof s1 should present in s2
print(s1 >= s2) #if s1 is superset of s2 or not IF true the s1 should have all the element present in s2
print(s1.issuperset(s2))
print(s1>s2) #propersuperset