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
Consider:
a = [1,2,2,3,4,5]
To take out all occurrences, you could use the filter function in python. For example, it would look like:
a = list(filter(lambda x: x!= 2, a))
So, it would keep all elements of a != 2.
a != 2
To just take out one of the items use
a.remove(2)