Codele / Data structures
Grids and matrices
A cinema seating plan has rows and columns. A computer keeps it as a list of lists: one small list for each row.
- A grid (or matrix) is a list of lists: each inner list is one row.
- Read one cell with two numbers: plan[row][column]. Both start at 0.
- A loop inside a loop visits every cell: the outer loop picks the row, the inner loop walks along it.
- Counting means keeping a tally and adding one each time a cell passes the test.
- Noughts and crosses, chess boards and pictures made of pixels are all grids.
Loading the playable lesson…