[ActionMap] Fix bug introduced here: bd31f21021bc7b8f42b2eabdb780410a…

Status
Not open for further replies.

GitHub

Moderator
[ActionMap] Fix bug introduced here: bd31f21021bc7b8f42b2eabdb780410a2a9fecc8

Do not modify the list as it is being iterated.

Using "unknown[:]" means a copy of the list is being iterated.

To demonstrate the bug, first the wrong code:

>>> myList = [1,2,3,4,5]
>>> for i in myList:
... if i in (3,4):
... myList.remove(i)
...
>>> myList
[1, 2, 4, 5]
>>>

And now with the correct original:

>>> myList = [1,2,3,4,5]
>>> for i in myList[:]:
... if i in (3,4):
... myList.remove(i)
...
>>> myList
[1, 2, 5]
>>>

Continue reading...
 
Status
Not open for further replies.
Back
Top