For my assignment, I need to insert a value into a particular index in a sublist of a list which contains 3 lists. Instead of changing the value in only 1 sublist, it changes it in every sublist.
I have tried reentering the values which are used to determine the indices.
def make_move(cur, move, player):
m0 = move[0]
m1 = move[1]
cur[m0][m1] = player
make_move(world, (1,0), 'X')
print(world)
I expect the output to be:
[['', '', ''], ['X', '', ''], ['', '', '']]
What I am receiving is:
[['X', '', ''], ['X', '', ''], ['X', '', '']]
I made the world function as follows:
def set_up_game(size):
n = 0
num = 0
s = int(get_game_size(size))
game = []
rows = []
columns = ''
while n < s:
rows.append(columns)
n += 1
while num < s:
game.append(rows)
num += 1
return game