Update transposition snippet (python)

zip is a nice trick but it doesn't output a matrix. The output of zip is an iterator of tuples. You can't use it for accessing elements of matrix by index.

`transposed_matrix[0][0]` will raise an error
`TypeError: 'zip' object is not subscriptable`
pull/634/head
Pavel 9 months ago committed by GitHub
parent f1bf1b61ec
commit 3f66dc7e13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

Loading…
Cancel
Save