行列$A$の転置と90°回転を求める。
A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
90°回転
結論
rotate = lambda A: [list(x)[::-1] for x in zip(*A)]
rotate(A) # [[7, 4, 1], [8, 5, 2], [9, 6, 3]]
転置
結論
transpose = lambda A: [list(x) for x in zip(*A)]
transpose(A) # [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
結論
zipは便利