0
$\begingroup$

Every element in List A appears only once, and the same is true for List B. How can I efficiently create a list of the element in A that don't appear in B? Obviously, I can just do this:

Do[A=DeleteDuplicates[A,B[[i]]],{i,1,Length[B]}];

...but that's painfully slow for very long lists. Also, it doesn't take advantage of my knowledge that every element in each list is unique within the list.

Thanks!

$\endgroup$
2
  • 7
    $\begingroup$ Complement[B, A] ? $\endgroup$
    – cvgmt
    Mar 7, 2021 at 23:15
  • $\begingroup$ @cvgmt Seriously, that simple? Well, if you want to post that as an Answer, I'll Accept it. $\endgroup$ Mar 7, 2021 at 23:17

1 Answer 1

11
$\begingroup$
A = RandomInteger[10, 10]
B = RandomInteger[10, 8]
Complement[A, B]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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