0
$\begingroup$

I would like to delete all elements of a list that are equalled to any element found in a bigger list.

For example, if I had A = {1,2,3,4,5} and B = {2,4,6,8,9,12}

I would like to get C = {1,3,5}

This is based on A dropping the number 2 and 4 because it is in List B.

$\endgroup$
  • 2
    $\begingroup$ look up Complement in the docs? $\endgroup$ – kglr Oct 14 '19 at 14:17
5
$\begingroup$

You can use Complement:

Complement[A, B]

{1, 3, 5}

Also

A /. Alternatives @@ B -> Nothing

{1, 3, 5}

and

DeleteCases[A, Alternatives @@ B]

{1, 3, 5}

Cases[Except[Alternatives @@ B]] @ A

{1, 3, 5}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.