-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8 CHAPTER 8 python.py
More file actions
85 lines (62 loc) · 2.21 KB
/
8 CHAPTER 8 python.py
File metadata and controls
85 lines (62 loc) · 2.21 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
81
82
83
# ***************************************************************************************************************************************************************************
# **************************************************************CH-8*************************************************************************************************************
# ***************************************************************************************************************************************************************************
# ***************************************************************************************************************************************************************************
# ***************************************************************************************************************************************************************************
# ***************************************************************************************************************************************************************************
# ***************************************************************************************************************************************************************************
# ======================================================== set data type ==============================================================
# set is unordered collections of unique items
# s = {1,2,2,3,3,5,5,7,8,4,4,4,4,3,3,2,5,6,7,5,9,9,8,5}
# print(s)
l = [1,2,2,4,4,6,7,8,7,5,7,7,5,8]
# remove duplicate
s2 = list(set(l))
print(s2)
print(type(s2))
# set method
# Add
s = {1,2,3,4}
s.add(5)
s.add(6)
print(s)
# remove method
s = {1,2,3,4}
s.remove(3)
print(s)
# discard method
s = {1,2,3,4}
s.discard(5)
print(s)
# clear method
s = {1,2,3,4}
s.clear()
print(s)
# copy method
s = {1,2,3,4}
s1 = s.copy()
print(s1)
# we can store in like
s = {1,1.0,2.4,"string"}
print(s)
# more about set
# in Keyword in set and for Loop
s = {'a','b','c'}
if 'a' in s:
print('present')
else:
print('not present')
# for loop
for item in s:
print(item)
# set maths
s1 = {1,2,3,4,5}
s2 = {4,5,6,7,8}
# two type of set
# 1. union
# 2. intersection
# | union
union_set = s1 | s2
print(union_set)
# intersection
print(s1 & s2)