I want to remove a value from a list if it exists in the list (which it may not).
a = [1, 2, 3, 4] b = a.index(6) del a[b] print(a)
The abov
Overwrite the list by indexing everything except the elements you wish to remove
>>> s = [5,4,3,2,1] >>> s[0:2] + s[3:] [5, 4, 2, 1]
More generally,
>>> s = [5,4,3,2,1] >>> i = s.index(3) >>> s[:i] + s[i+1:] [5, 4, 2, 1]