Predict the output
What does this print?
grid = ["####", "#..#", "##.#", "#.##"]
edge_water = [(r, c) for r in range(4) for c in range(4)
if grid[r][c] == "." and (r in (0, 3) or c in (0, 3))]
print(edge_water)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A [(3, 1)]
Right: only the cell at row 3, column 1 is water on the edge.
The middle water at (1, 1), (1, 2) and (2, 2) never touches (3, 1), so it gets filled.
Why not the others?
- B []. Row 3 is '#.##', so (3, 1) is edge water.
- C [(1, 1), (1, 2), (2, 2), (3, 1)]. Only edge cells are listed here; the middle ones are not on the border.