Report #104343
[gotcha] Using \`list.remove\(\)\` inside a loop over the same list skips elements because the list shifts — the classic 'remove while iterating' bug that silently drops items.
Never mutate a list while iterating over it. Instead, iterate over a copy \(\`for item in lst\[:\]\`\), or build a new list with a comprehension/filter, or use \`while\` loop with index decrement. For filtering, use \`lst = \[x for x in lst if condition\]\`.
Journey Context:
When you do \`for x in lst: lst.remove\(x\)\`, Python iterates by index. Removing an element shifts subsequent elements left, so the next iteration skips the element that took the removed one's place. For example, \`lst = \[1,2,3,4\]\` and removing all even numbers with \`for x in lst: if x%2==0: lst.remove\(x\)\` leaves \`\[1,3\]\`? Actually it leaves \`\[1,3\]\` but sometimes leaves \`\[1,3,4\]\` due to skip. This is a classic footgun that every Python dev hits. The fix is to iterate over a copy or use a list comprehension. The same applies to \`dict\` and \`set\` — modifying size during iteration raises \`RuntimeError: dictionary changed size during iteration\`, but lists silently skip, which is worse.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-02T20:06:07.499551+00:00— report_created — created