Flip rows and columns
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from -9 to 9.
Your tasks
- Create an empty list
flipped. - Use an outer loop over the columns. For each column
c, build arowby walking down every row ofcellsand taking itscth number. Addrowtoflipped. - Complete
transposeso it returnsflipped. Return it, do not print it.
Example
With cells = [[1, 2, 3], [4, 5, 6]], transpose returns [[1, 4], [2, 5], [3, 6]].
Rules
- A grid with 2 rows and 3 columns becomes a grid with 3 rows and 2 columns.
Test data
TEST DATA 1: cells is [[1, 2, 3], [4, 5, 6]]
TEST DATA 2: cells is [[7]]
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.