forked from kpbochenek/empireofcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranspose_matrix.py
26 lines (21 loc) · 881 Bytes
/
transpose_matrix.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
# kpbochenek@gmail.com
def transpose(data):
transposed = []
for i in range(len(data[0])):
transposed.append([t[i] for t in data])
return transposed
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert transpose([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]) == [[1, 4, 7],
[2, 5, 8],
[3, 6, 9]], "Square matrix"
assert transpose([[1, 4, 3],
[8, 2, 6],
[7, 8, 3],
[4, 9, 6],
[7, 8, 1]]) == [[1, 8, 7, 4, 7],
[4, 2, 8, 9, 8],
[3, 6, 3, 6, 1]], "Rectangle matrix"
print("Use 'Check' to earn sweet rewards!")