Python for loop skipping every other value

后端 未结 2 1373
醉话见心
醉话见心 2021-01-23 15:59

I have run into an odd problem in my django application where a for loop is skipping every other item. I have take a returned queryset and list()ed to iterate over.

2条回答
  •  终归单人心
    2021-01-23 16:24

    temp and items refer to the same object, so when you do items.remove() you're also modifying temp. You probably want to do temp = items[:] to copy the values of the items list.

提交回复
热议问题