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
With a for loop and a condition:
def cleaner(seq, value):
temp = []
for number in seq:
if number != value:
temp.append(number)
return temp
And if you want to remove some, but not all:
def cleaner(seq, value, occ):
temp = []
for number in seq:
if number == value and occ:
occ -= 1
continue
else:
temp.append(number)
return temp