Matrix Transpose

Matrices are often transformed so rows become columns and columns become rows, like turning a table for a different view of the same data. Write a function transpose that receives a matrix of numbers. Return a new matrix where the rows and columns have been swapped.

Примеры

Ввод
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Вывод
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
Ввод
[[1, 2, 3], [4, 5, 6]]
Вывод
[[1, 4], [2, 5], [3, 6]]
Ввод
[[1]]
Вывод
[[1]]

Нужно реализовать

def transpose(matrix: list[list[int]]) -> list[list[int]]:

Теги

arraymath
PostgreSQLv16

Aquí aparecerá el resultado de la ejecución del código

Visible tests
1
Input
[[1,2,3],[4,5,6],[7,8,9]]
Expected[[1,4,7],[2,5,8],[3,6,9]]
2
Input
[[1,2,3],[4,5,6]]
Expected[[1,4],[2,5],[3,6]]
3
Input
[[1]]
Expected[[1]]
4
Input
[[1,2],[3,4]]
Expected[[1,3],[2,4]]
5
Input
[[5,6,7]]
Expected[[5],[6],[7]]
6
Input
[[1],[2],[3]]
Expected[[1,2,3]]
Focus radio
Paused · SomaFM · Fluid