-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflip_vertical_axis.py
More file actions
39 lines (31 loc) · 893 Bytes
/
flip_vertical_axis.py
File metadata and controls
39 lines (31 loc) · 893 Bytes
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
def flip_vertical_axis(matrix):
"""
offset for left side = index - 0
offset for right side = length - index - 1
new position for left = length - offset - 1
new position for right = offset
"""
def flip(rows):
length = len(rows) - 1
midpoint = length // 2
temp = None
for index in range(0, midpoint + 1):
offset = index - 0
right_pos = length - offset
left_pos = offset
temp = rows[right_pos]
rows[right_pos] = rows[left_pos]
rows[left_pos] = temp
for rows in matrix:
flip(rows)
return matrix
TEST = flip_vertical_axis([[1, 0, 2, 4], [1, 3, 5, 7]])
print(TEST)
"""
Optimal solutions:
for rows in matrix:
rows.reverse()
for i in range(len(matrix)):
matrix[i] = matrix[i][::-1]
built in methods for reversing
"""