Python list.remove() skips next element in list

前端 未结 6 1735
夕颜
夕颜 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条回答
  •  萌比男神i
    2020-12-16 01:39

    Don't modify lists that you are iterating over!

    Instead, do something like:

    for square in squares[:]:
    

    so that you're iterating over a copy of the list while still changing the original.

提交回复
热议问题