Lets say I have a list a
:
a = [[1, 1], [2, 2], [1, 1], [3, 3], [1, 1]]
Is there a function that removes all instances of [1, 1]
?
If you want to modify the list in-place,
a[:] = [x for x in a if x != [1, 1]]
Use a list comprehension:
[x for x in a if x != [1, 1]]
Google finds Delete all items in the list, which includes gems such as
from functools import partial
from operator import ne
a = filter(partial(ne, [1, 1]), a)
def remAll(L, item):
answer = []
for i in L:
if i!=item:
answer.append(i)
return answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With