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

**URL:** <https://onehack.st/t/how-can-i-make-a-loop-to-perform-action-on-neighbours-of-my-start-box-in-python/159384>\
**Category:** Discussion & Solutions\
**Tags:** solved, programming\
**Created:** [October 19, 2020, 8:48am UTC](https://onehack.st/t/how-can-i-make-a-loop-to-perform-action-on-neighbours-of-my-start-box-in-python/159384 "2020-10-19T08:48:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurav\_P](https://onehack.st/user_avatar/onehack.st/saurav_p/32/24576_2.png) [@Saurav\_P](https://onehack.st/u/Saurav_P)\
**Post date:** [October 19, 2020, 8:48am UTC](https://onehack.st/t/how-can-i-make-a-loop-to-perform-action-on-neighbours-of-my-start-box-in-python/159384/1 "2020-10-19T08:48:14Z")

</div>

I have made a grid using for loop and pygame

![](https://i.stack.imgur.com/aNUjv.png)

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.

---

<div class="post-metadata">

**Author:** ![Parizaad](https://onehack.st/user_avatar/onehack.st/parizaad/32/174871_2.png) [@Parizaad](https://onehack.st/u/Parizaad)\
**Post date:** [November 18, 2020, 11:54am UTC](https://onehack.st/t/how-can-i-make-a-loop-to-perform-action-on-neighbours-of-my-start-box-in-python/159384/2 "2020-11-18T11:54:44Z")

</div>

- Please read the FAQ \>\>\> [https://onehack.st/faq](https://onehack.st/faq)

> # 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**! 🙁

> <https://stackoverflow.com/questions/33963361/how-to-make-a-grid-in-pygame>

> <https://stackoverflow.com/questions/41960363/creating-a-grid-in-pygame-using-for-loops>

> <https://stackoverflow.com/questions/30285857/very-simple-pygame-grid-program-how-do-i-get-the-boxes-around-the-clicked-grid>
