Created
September 30, 2019 20:30
-
-
Save RafaelBroseghini/a8705183262e8ac4607b95736410f6ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix = [ | |
[1,2,3], | |
[4,5,6] | |
] | |
def transpose(matrix: list) -> list: | |
if len(matrix) == 0: | |
return [] | |
rows, cols = len(matrix), len(matrix[0]) | |
new_matrix = [[None] * rows for i in range(cols)] | |
for r in range(rows): | |
for c in range(cols): | |
new_matrix[c][r] = matrix[r][c] | |
return new_matrix | |
print(transpose(matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment