# How to delete elements while traversing the list in processing.py?

**URL:** <https://discourse.processing.org/t/how-to-delete-elements-while-traversing-the-list-in-processing-py/21041>\
**Category:** Processing.py\
**Created:** [May 19, 2020, 4:06am UTC](https://discourse.processing.org/t/how-to-delete-elements-while-traversing-the-list-in-processing-py/21041 "2020-05-19T04:06:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 19, 2020, 4:13am UTC](https://discourse.processing.org/t/how-to-delete-elements-while-traversing-the-list-in-processing-py/21041/2 "2020-05-19T04:13:57Z")

</div>

> [@\[SOLVED\] Py.processing bullet and enemy collision](https://discourse.processing.org/t/solved-py-processing-bullet-and-enemy-collision/8327/4):
>
> @solub, your solution is buggy! bug When we delete an item from a list, all elements w/ a higher index than the deleted item got their indices subtracted by 1! face_with_monocle They’re left-shifted, and therefore, the next iteration skips an item; which now got the same index as the just deleted item. arrow_left You can see that bug in this sample loop below: eye : nums = list(range(10)) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for n in nums: print n nums.remove(n) print nums # [1, …

---

_[View the full topic](https://discourse.processing.org/t/how-to-delete-elements-while-traversing-the-list-in-processing-py/21041)._
