-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
55 lines (42 loc) · 1.11 KB
/
list.py
File metadata and controls
55 lines (42 loc) · 1.11 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
# colors.append("yellow")
# #thêm append là vào vị trí cuối
# for i in range(len(colors)):
# print(colors[i])
# last_index = len(colors)-1
# print(colors[-1])
colors = ["red", "blue", "green", "gray", "red", "red"]
print(colors)
# remove from list
try:
colors.remove("blue")
except:
print("Not exist")
print(colors)
#bỏ đi cái cuối cùng (remove last element)
colors.pop()
print(colors)
#Thêm 1 element vào vị trí thứ ...
colors.insert(0,"black")
print(colors)
colors.insert(1,"purple")
print(colors)
#tìm vị trí thứ ? của 1 element (red)
print(colors.index("red"))
#tìm tất cả các vị trí của 1 element (red)
red_index = []
for i in range(len(colors)):
if colors[i] == "red":
red_index.append(i)
print("The word 'red' occurs at the following index: ", end = " ")
print(red_index)
#find number of occurance of "red"
# đếm số phần tử tên red trong list
print(colors.count("red"))
#Sắp xếp
print("Sort Example: ")
a = [1,2,10,3,5,7]
a.sort()
print(a)
#change the first element to 'Dat'
a[0] = "Dat"
print(a)