How can I make a loop to perform action on Neighbours of my start box in python?

I have made a grid using for loop and pygame

and I have also connected it to a 2d-array. I have converted x, y into rows and columns according to the blocks.

now the green block represents the start position and I have to perform actions on its neighbors i.e all blocks touching it(even the corner blocks)

I wanted to know is there a more efficient solution to this as currently I am just storing them one-by-one in a list and then perform actions on it.

and to get the row and column of each it takes a lot of code so please help I am a beginner.

What Kind of “help” Queries Are Not Allowed?

  • How to code this, can you help me with a coding script? I am stuck with code, now what to do? how to crack, find crack/patch, crack this or that <<< Please, avoid asking such deep programming language questions, as there is already a website dedicated for this stackoverflow ! :slightly_frowning_face: