Removing elements from an array that are in another array

there is an easy solution with a list comprehension,

A = [i for i in A if i not in B]


[[1, 1, 2], [1, 1, 3]]

List comprehension is not removing the elements from the array, it’s just reassigning – if you want to remove the elements, use this method:

for i in B:
     if i in A:

Leave a Comment