4/32
Part 1 of 7 · A grid is a graphLearn and do

In Python a negative index reads the far side of the grid, so check both bounds

Before the search itself, one Python trap in reading a cell's neighbors.

grid = ["....",
        "####",
        "F..."]
r = 0
print(grid[r - 1])
F...

For a cell in the top row, the row above is row -1. Python doesn't raise an error for it. It counts a negative index from the end, so grid[-1] is the bottom row:

What a top-row cell sees when it looks up
grid
row -1F...row 0....row 1####row 2F...

Row -1 isn't a real row: Python reads row 2 there, so a cell in row 0 looks up and finds a fire.

That's why the bounds check is the line that's easy to get half right. Check both ends: 0 <= nr < len(grid) and 0 <= nc < len(grid[0]).

In the editor, write open_neighbors(grid, r, c): neighbors from the top of this part, with both bounds checked and rocks # left out. Every search below calls it.