Q:

Python: updating a single item in a list, updates the entire list

I have a piece of code that should be updating a single item in a list but instead updates the entire list. 
Here is the code
a = [
  [(0, 0), (3, 4)]
]
board = [[0] * 5] * 5

for solution in a:
    for _x, _y in solution:
        board[_x][_y] = 1

print(board)

Expected output:
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0

Actual output:
1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

1 0 0 0 1

A:

Your problem resides in this line:
board = [[0] * 5] * 5

[[0] * 5] * 5 replicates the resulting list of [0, 0, 0, 0, 0] five times so that the reference remains the same across the board:
print([id(i) for i in board])
[59200896, 59200896, 59200896, 59200896, 59200896]

This makes it impossible to make the change individually.
Instead, do this:
board = [[0] * 5 for _ in range(5)]

print([id(i) for i in board])
[45118008, 45045120, 43900680, 43899760, 45119088]

The list comprehension will create a distinct object reference for each inner list, and the objects can now be updated individually:
[
  [1, 0, 0, 0, 0],
  [0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1],
  [0, 0, 0, 0, 0]
]

