Declare the coordinate convention
grid[row][column] first selects a row, then a value within that row. A 2 × 3 grid has row indices 0–1 and column indices 0–2. State whether a report uses zero-based indices or human-friendly numbering.
Week 08 / Organise observations
Keep the location attached to the value.
A list preserves order along one sequence. A thermal map needs two coordinates: which row and which column contain a reading?
A small thermal map has rows [22, 23, 24] and [25, 80, 26], all in °C. Rows run top to bottom and columns left to right.
Start with the problem
Draw the two rows, circle the hottest sample and label its row and column starting from zero. Could a report containing only “80 °C” tell someone where to look?
Nested lists hold rows of readings. Nested loops visit every row–column pair, allowing the value and its coordinates to stay together.
By the end: Report the peak as a temperature and a row–column pair. Explain why those indices are not physical distances.
grid[row][column] first selects a row, then a value within that row. A 2 × 3 grid has row indices 0–1 and column indices 0–2. State whether a report uses zero-based indices or human-friendly numbering.
The outer loop selects a row; the inner loop visits its columns. Track value and location together. If you remember only the maximum, you lose the location that makes the result actionable.
A transpose swaps rows and columns. It preserves numeric values but changes their coordinate interpretation. Ragged rows violate a rectangular-grid assumption and need an explicit policy before processing.
Read the example alongside the explanation. Run it in a new notebook cell and change one input to see how it behaves.
grid_c = [[22, 23, 24], [25, 80, 26]]
peak = grid_c[0][0]
location = (0, 0)
for row in range(len(grid_c)):
for col in range(len(grid_c[row])):
if grid_c[row][col] > peak:
peak = grid_c[row][col]
location = (row, col)
print('Peak (C):', peak)
print('Zero-based row, column:', location)Peak (C): 80 Zero-based row, column: (1, 1)
grid[row][column] first chooses a row object and then an element in it. A nested traversal should preserve the coordinates associated with each reading. Index numbers are positions in a representation, not physical distances.
Draw [[22, 23, 24], [25, 80, 26]] as a two-row, three-column table. Label row and column indices from zero.
Predict before running. Where is 80? What information is lost if the report returns only the largest value?
The peak is 80 at row 1, column 1. The six visits follow the grid shape. For ragged rows, each row can have a different length; a rectangular assumption must be stated and checked.
Change one thing. Place another 80 at (0, 2). Decide whether the required result is the first maximum, last maximum or all maxima. That choice determines how equal values are handled.
Türkçe: İndis değerin konumudur, fiziksel uzaklık değildir. Eşit maksimumlarda hangi konumun döndürüleceğini önceden belirle.
Each example changes something about the same problem. Open the ones you want to explore and follow the worked explanation.
Rows: [22, 23, 24] and [25, 80, 26] °C
Question: Locate the maximum using zero-based row and column.
In human numbering this is the second row and second column. Say which convention you use.
Rows: [22, 23, 90] and [25, 24, 26] °C
Question: Would swapping row and column give a valid original position?
An asymmetric case catches a row/column mistake that the original (1, 1) case hides.
Rows: [80, 23, 24] and [25, 80, 26] °C
Question: Which peak does the model keep with a strict > comparison?
The model returns the first maximum, not every hot spot. A report should disclose that tie policy.
Interactive walkthroughs of 2D Lists & Nested Loops. Enable JavaScript to step through code, variables, collections and output. The companion notebook remains available below.
Use the notebook to try the ideas yourself. The steps below connect this week's example to the programming practice.
Something to take away: An annotated map, the peak with coordinates, and a test that exposes a swapped-coordinate implementation.
Read the notebook's teaching cells before these exercises.
Use the notebook's core and optional labels to choose your workload. This activity fits within guided class time.
Notes stay in this browser. Download a copy to keep them.
Ask AI to locate the maximum in a grid. Test it on a non-square grid with an off-centre maximum and on tied peaks. Ask it to state its tie policy instead of claiming it found all hot spots.
You can also review the supplied example with a partner. Use the same inputs to compare the reasoning. Follow the syllabus rules for assessed work.