Transpose a grid · Transposisi grid
Transpose a grid
Swap the rows and columns of a grid, as if you reflected a table across its diagonal.
grid[r][c] is the item in row r and column c. The new grid has one row for each column of the old one, so loop over the column numbers first, and inside that loop collect row[col] from every row.
Transpos matriks
Tukar baris dan kolom matriks, seolah-olah Anda memantulkan tabel melintasi diagonalnya.
grid[r][c] adalah item di baris r dan kolom c. Matriks baru memiliki satu baris untuk setiap kolom matriks lama, jadi loop melalui nomor kolom terlebih dahulu, dan di dalam loop tersebut kumpulkan row[col] dari setiap baris.
Write transpose(grid) that turns rows into columns. grid is a list of rows, all the same length. [[1, 2, 3], [4, 5, 6]] becomes [[1, 4], [2, 5], [3, 6]]. · Tulis transpose(grid) yang mengubah baris menjadi kolom. grid adalah daftar baris, semua panjangnya sama. [[1, 2, 3], [4, 5, 6]] menjadi [[1, 4], [2, 5], [3, 6]].
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.