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:


...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.


  • 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

A = RandomInteger[10, 10]
B = RandomInteger[10, 8]
Complement[A, B]

Your Answer

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

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