Dapatkan sel yang berdekatan dalam 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

pi junky