mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-04-29 13:02:23 +08:00
contents/matrix: transposition snippet (python) (#634)
This commit is contained in:
@@ -59,7 +59,7 @@ Many grid-based games can be modeled as a matrix, such as Tic-Tac-Toe, Sudoku, C
|
|||||||
Transposing a matrix in Python is simply:
|
Transposing a matrix in Python is simply:
|
||||||
|
|
||||||
```py
|
```py
|
||||||
transposed_matrix = zip(*matrix)
|
transposed_matrix = [[matrix[i][j] for i in range(len(matrix))] for j in range(len(matrix[0]))]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Essential questions
|
## Essential questions
|
||||||
|
|||||||
Reference in New Issue
Block a user