$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #71

What is the correct fix?

grid = [[0] * 3] * 3
grid[0][0] = 5
print(grid[1][0])
  1. Build rows: [[0] * 3 for _ in range(3)]
  2. Build rows: [[0] for _ in range(3) * 3]
  3. Change grid[0][0] = 5 to append a row
  4. Wrap the outer list in list(grid) first
* 3 repeats the SAME inner list three times, so one write appears in every row.
Play Problem Solving ▸