0

I don't understand why copied list is still changing with the original one when i am using right copy syntax

from random import randint


def place_one(maps):
    x = randint(0,4)
    y = randint(0,4)
    while True:
        if maps[x][y] == 'O':
            maps[x][y] = 'J'
            break
        else:
            x = randint(0,4)
            y = randint(0,4)


computer_map = []
player_map = []
for x in range(5):
    computer_map.append(['O', 'O', 'O', 'O', 'O'])
    player_map.append(['O', 'O', 'O', 'O', 'O'])
computer_hidden_map = computer_map[:]
place_one(computer_hidden_map)
print(computer_map)
print(computer_hidden_map)
Fr0glem
  • 33
  • 2
  • 4
    You're making a *shallow* copy of a *nested* list... – jonrsharpe Apr 29 '16 at 20:55
  • Also see [Original list gets modified in python](http://stackoverflow.com/questions/33702358/original-list-gets-modified-in-python) for a duplicate more closely related to your question (copy of a nested list). – Lukas Graf Apr 29 '16 at 20:58

0 Answers0