I have a list of lists, something like
[[1, 2, 3,],[4, 5, 6,],[7, 8, 9]]
.
Represented graphically as:
1 2 3
4 5 6
7 8 9
I'm looking for an elegant approach to checking the value of neighbours of a cell, horizontally, vertically and diagonally. For instance, the neighbours of [0][2] are [0][1], [1][1] and [1][2] or the numbers 2, 5, 6.
Now I realise I could just do a bruteforce attack checking every value a la:
[i-1][j]
[i][j-1]
[i-1][j-1]
[i+1][j]
[i][j+1]
[i+1][j+1]
[i+1][j-1]
[i-1][j+1]
But thats easy, and I figured I can learn more by seeing some more elegant approaches.