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$

closed as off-topic by Alexey Popkov, C. E., Michael E2, m_goldberg, MarcoB Oct 15 at 1:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Alexey Popkov, C. E., Michael E2, m_goldberg, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ look up Complement in the docs? $\endgroup$ – kglr Oct 14 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.