简单列表复制和共享引用python

时间:2016-04-29 20:53:33

标签: python list

当我使用正确的复制语法时,我不明白为什么复制列表仍在使用原始列表进行更改

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)

0 个答案:

没有答案
相关问题