我需要用作用于列表每个位置的函数“counterPosition”的相应输出值替换列表阵营的所有元素
camp = [[True, False, False, False, False, True],
[False, False, False, False, False, True],
[True, True, False, True, False, True],
[True, False, False, False, False, False],
[False, False, True, False, False, False],
[False, False, False, False, False, False]]
def counterPosition(x, y):
bombs = 0
for i in range(x-1, x+2):
for j in range(y-1, y+2):
if i<0 or j<0: continue
elif camp[i][j] == True:
bombs += 1
return bombs
for x in range (len(camp)):
for y in range (len(camp[x])):
camp[x][y] = counterPosition(x,y)
print camp
这使:
IndexError: list index out of range