how to find the neighbors of an element in matrix python
mat = "NxN matrix"
a, b = (2, 3) # the index of the element
neighbors = [mat[i][j] for i in range(a-1, a+2) for j in range(b-1, b+2) if i > -1 and j > -1 and j < len(mat[0]) and i < len(mat)]