-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset.py
More file actions
60 lines (48 loc) · 1.12 KB
/
Copy pathset.py
File metadata and controls
60 lines (48 loc) · 1.12 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
# set
# loop for a set
a={"hello","vikrant","welcome"}
print(a)
print(type(a))
for x in a:
print(x)
print("hello" in a)
# add item
a.add("OK")
print(a)
b={"Zero","work","done"}
a.update(b)
print(a)
# can add any type of list in it
c=[67,87,90]
a.update(c)
print(a)
# removing an item
# by using REMOVING to reove an item for a set if the item doesnt in the list then it will show an error. the item tou want to remove must be in the set to be remove.
a.remove("hello")
print(a)
# use discard to remove so it doesnot show any error while removing an item. it exist in the set or not it will remove it.
a.discard("welcome")
print(a)
# joining 2 set. must use a new set for output.
d={67,4356,345,2345,20}
e={54,63,20,345,34,00,67}
f=d.union(e)
print(f)
# also can use update
d.update(e)
print(d)
# both update and union will remove any duplicate item in it.
# intersection
d.intersection_update(e)
print(d)
#for optput in a new variable.
z=d.intersection(e)
print(d)
#symmetric_difference
x={98,89,756,87}
y={78,87,76,8876}
x.symmetric_difference_update(y)
print(x)
# for answer in new vaariable
j=x.symmetric_difference(y)
print(j)