Grids and matrices
A grid locates an item with two coordinates. Pick a row, then a column within that row.
Simple example
The top row contains 4 and 7. The bottom row contains 2 and 9. Store the rows one after the other. Skip the two cells of the top row, then move one position across to print 9.
cells = [4, 7, 2, 9]
columns = 2
row = 1
column = 1
print(cells[row * columns + column])
9
Everyday examples
Read a cinema seat map
In two cinema rows the ticket numbers are 11, 12 and 21, 22. Which ticket is in the second seat of the back row?
Select the back row first. Its second seat contains ticket 22.
Water one garden bed
The moisture readings in two garden rows are 3, 6 and 5, 8. Which reading belongs to the front-left bed?
The front row is listed first and the left bed is its first column. Read 3.
Find a timetable entry
Two days each have morning and afternoon classes. Their room numbers are 5, 8 and 6, 9. Where is the second-day morning class?
Use the second day's row and the morning column. Room 6 is the intersection.
Cost and limits
Check both coordinates. With a rectangular array, a valid cell is directly accessible. A jagged list can have different row lengths.