This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients WoodyWoo, eric.smith, serhiy.storchaka
Date 2020-09-30.14:43:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601476991.17.0.492597160685.issue41892@roundup.psfhosted.org>
In-reply-to
Content
You will get the same behavior for lists:

>>> a = [1, 2, 3]
>>> for x in a:
...     if x == 1:
...         a.remove(x)
...     print(x)
... 
1
3

Lists are iterated by index. First you get an item at index 0, then at index 1, etc, to the end of the list. Initially the list is [1, 2, 3]. After removing 1 at the first iteration it becomes [2, 3], and at the next iteration you get an item at index 1 which is 3.
History
Date User Action Args
2020-09-30 14:43:11serhiy.storchakasetrecipients: + serhiy.storchaka, eric.smith, WoodyWoo
2020-09-30 14:43:11serhiy.storchakasetmessageid: <1601476991.17.0.492597160685.issue41892@roundup.psfhosted.org>
2020-09-30 14:43:11serhiy.storchakalinkissue41892 messages
2020-09-30 14:43:11serhiy.storchakacreate