0

I am making a connect 4 game for a project but am coming unstuck as I cannot figure out the arrays in Python, as I am making a shallow copy of GameArrays[0] in this test but when I add the Y to the last index it applies to all the indices of the GameArrays list, how can i make it so that it only applies to the one i want.

Code

Width = 6
Height =5
EmptyRow=[]
EmptyRow = [0 for i in range(Height)] 

GameArrays=[]
for x in range(Width):
  GameArrays.append(EmptyRow)
x=0
playedIn=GameArrays[0]


playedIn.pop(0)
playedIn.append("Y")

GameArrays[0]=playedIn
print(GameArrays)

Desired Output

[[0, 0, 0, 0, Y], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

Actual Output

[[0, 0, 0, 0, 'Y'], [0, 0, 0, 0, 'Y'], [0, 0, 0, 0, 'Y'], [0, 0, 0, 0, 'Y'], [0, 0, 0, 0, 'Y'], [0, 0, 0, 0, 'Y']]

0 Answers0