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
We can also use .pop:
>>> lst = [23,34,54,45] >>> remove_element = 23 >>> if remove_element in lst: ... lst.pop(lst.index(remove_element)) ... 23 >>> lst [34, 54, 45] >>>