-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.py
43 lines (34 loc) · 911 Bytes
/
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
# Indexing and slicing
new_list = [0, 1, 2, 3,9,6,4]
print(new_list[4])
#from to
print(new_list[1:3])
# all before index :x
print(new_list[:2])
# all after index x:
print(new_list[2:])
print()
movies = ['Avengers', 'Black Panther', 'Thor']
movies[0] = 'Captain America'
movies.append('Sorry to Bother You') # Adds item to end of list
print(movies)
movies.insert(1, "Wont You Be My Neighbour") # Adds item to list at index
print(movies)
movies.remove('Thor')
print(movies)
# More list methods
print("more list methods",new_list)
new_list.insert(1, True) # Lists can hold any type of data
new_list.extend([1, 2, 3])
print(new_list)
new_list.reverse()
print(new_list)
print(new_list.count(1)) # Remember, 1 == True
new_list.sort()
print(new_list)
# Nested lists can be used for matrices
matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
matrix[1][0] = 1000
print(matrix)