Skip to content

Instantly share code, notes, and snippets.

@RafaelBroseghini
Created September 30, 2019 20:30
Show Gist options
  • Save RafaelBroseghini/a8705183262e8ac4607b95736410f6ca to your computer and use it in GitHub Desktop.
Save RafaelBroseghini/a8705183262e8ac4607b95736410f6ca to your computer and use it in GitHub Desktop.
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