get adjacent cells in grid

x = 5
y = 5
#just add the target x and y to row and col to get adjacent positions
adjacent_positions = [[row + x ,col + y] for row in (-1,0,1) for col in (-1,0,1) if [row + x ,col + y] != [x,y]]
#output
#[[4, 4], [4, 5], [4, 6], [5, 4], [5, 6], [6, 4], [6, 5], [6, 6]]

#NOTE: without the if statement would produce a list including the target x and y

Here is what the above code is Doing:
1. We create a list of lists, where each list is a pair of coordinates.
2. We iterate over the range of -1, 0, and 1 for both the row and column.
3. We add the target row and column to the current row and column.
4. We add the resulting list to our list of lists.
5. We filter out the list that contains the target row and column.
6. We print the resulting list.