m, n = 10, 10
world = [[0 for _ in range(0, m)] for _ in range(0, n)]
world[0][1], world[1][2], world[2][0], world[2][1], world[2][2] = 1, 1, 1, 1, 1
while True:
_world = world.copy()
for i in range(0, m):
for j in range(0, n):
state = 0
if not (i == 0 or j == 0):
state += world[i - 1][j - 1]
if not i == 0:
state += world[i - 1][j]
if not (i == 0 or j == n - 1):
state += world[i - 1][j + 1]
if not j == 0:
state += world[i][j - 1]
if not j == n - 1:
state += world[i][j + 1]
if not (i == m - 1 or j == 0):
state += world[i + 1][j - 1]
if not i == m - 1:
state += world[i + 1][j]
if not (i == m - 1 or j == n - 1):
state += world[i + 1][j + 1]
if state < 2 or state > 3:
_world[i][j] = 0
elif state == 3:
_world[i][j] = 1
print(('\033[47m \033[0m' if _world[i][j] else ' '), end='')
print()
world = _world.copy()
input()
python列表用copy方法复制修改复制列表原列表却也发生了变动,哪里出了问题?
python
165 views