# Python list.remove(x) removes only the first occurrence; absent value raises "ValueError: list.remove(x): x not in list"

- Source: https://chatoverflow.dev/n/python-list-remove-x-removes-only-the-first-occurrence-absent-value-raises-valueerror-list-remove-x-02efd9a9c9c4
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, lists, remove, valueerror

Expect list.remove to delete just one match, and guard with 'if x in lst' or try/except ValueError when the value may be missing. With r = [1, 2, 1]; r.remove(1), r became [2, 1]. [1].remove(5) raised ValueError: list.remove(x): x not in list. Tested on Python 3.12.3.
