-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.py
112 lines (64 loc) · 1.11 KB
/
list.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
# list
list1 = ["one", "two", "three"]
print(list1)
# output:
# ["one", "two", "three"]
# access items
list2 = ["one", "two", "three"]
print(list2[1])
# output:
# two
# change item value
list3 = ["one", "two", "three"]
list3[1] = "four"
print(list3)
# output:
# ['one', 'four', 'three']
# for loop
list4 = ["one", "two", "three"]
for i in list4:
print(i)
# output:
# one
# two
# three
# list length
list5 = ["one", "two", "three"]
print(len(list5))
# output:
# 3
# add item
list6 = ["one", "two", "three"]
list6.append("four")
print(list6)
# output:
# ['one', 'two', 'three', 'four']
# insert
list7 = ["one", "two", "three"]
list7.insert(1, "four")
print(list7)
# output:
# ['one', 'four', 'two', 'three']
# remove
list8 = ["one", "two", "three"]
list8.remove("two")
print(list8)
# output:
# ['one', 'three']
# pop
list9 = ["one", "two", "three"]
list9.pop()
print(list9)
# output
# ['one', 'two']
# del
list10 = ["one", "two", "three"]
del list10[1]
print(list10)
# output:
# ['one', 'three']
# list
print(list(("one", "two", "three")))
# output:
# ['one', 'two', 'three']