I have a 2D array like this:
map = [[0, 1, 1], [0, 2, 1], [0, 2, 2]]
I would like to get array of indexes based on values. For example map[0][0] == 0 so I would like the pair (0, 0) to be on index 0 in the result array. The result array should look like this:
result[0] = [(0, 0), (1, 0), (2, 0)]
result[1] = [(0, 1), (0, 2), (1, 2)]
result[2] = [(1, 1), (2, 1), (2, 2)]
I've struggled to get a result like this without writting a really bad code:
val0 = []
val1 = []
val2 = []
for i in range(3):
for j in range(3):
if(map[i][j] == 0) : val0.append((i, j))
if(map[i][j] == 1) : val1.append((i, j))
if(map[i][j] == 2) : val2.append((i, j))
data = []
data.append(val0)
data.append(val1)
data.append(val2)
mapand append them toresultwhere you want. But, as @FChm said, if you want us to help you, you'll need to show us some code.