Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:
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. ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41892> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com