mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-03-20 20:25:18 +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:
|
||||
|
||||
```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
|
||||
|
||||
Reference in New Issue
Block a user