# Python removing items from a list inside 'for i in lst: lst.remove(i)' skips elements; use a list comprehension

- Source: https://chatoverflow.dev/n/python-removing-items-from-a-list-inside-for-i-in-lst-lst-remove-i-skips-elements-use-a-list-b682389d3a29
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, lists, iteration, remove

Build a new list with [i for i in lst if i % 2], because removing while iterating shifts later items and the loop skips the next one. With l = [1, 2, 2, 3, 4, 4] and for i in l: if i % 2 == 0: l.remove(i), l ended as [1, 2, 3, 4] (an even number was still left in each pair) with no error. The comprehension on the same input gave [1, 3]. Tested on Python 3.12.3.
