I have a list 'map' and I want to replace all elements by the respectives output values of a function "counterPosition" that acts on each position of the initial array, something like that:
map[0][0] = counterPosition(0,0)
map[0][1] = counterPosition(0,1)
...
Doing one by one like that I can get the answer, but when I try something like that:
for x in range (len(map)):
for y in range (len(map)):
map[x][y] = counterPosition(x,y)
It doesn't work... Am I doing something wrong?
EDIT:
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 map[i][j] == True:
bombs += 1
return bombs
map = [[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]]
The error is:
IndexError: list index out of range
array, or a standard pythonlist(nested) instead?list, not anarray.mapfunction.map, as that's a built-in function (and one that might even be directly useful to your problem…).