Python list.remove() skips next element in list

前端 未结 6 1733
夕颜
夕颜 2020-12-16 01:27

Python, but not programming, newbie here. I\'m programming with lists and have run into an interesting problem.

width = 2
height = 2

# Traverse the board
de         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 01:50

    You are removing from a list while iterating over it. This is not a good idea.
    There are other ways to do what you are trying, one of which is to track the list indices of all items that you want to remove from the list and then remove them outside your for-loop

提交回复
热议问题