4
$\begingroup$

This problem was easy I thought, but I can't solve it, I have two lists

t = Range[{5, 7}]
k = {{3, 5},{2,7}}

and I want to get

{Complement[Range[5], {3, 5}],Complement[Range[7], {2, 7}]}

giving {{1, 2, 4}, {1, 3, 4, 5, 6}} I tried double pure functions, but to no avail

$\endgroup$

1 Answer 1

5
$\begingroup$

For this you'll want MapThread:

MapThread[Complement, {t, k}]

{{1, 2, 4}, {1, 3, 4, 5, 6}}

$\endgroup$
2
  • 1
    $\begingroup$ +1 Also, Complement @@@ Transpose[{t, k}] $\endgroup$
    – Bob Hanlon
    Sep 7, 2020 at 13:26
  • $\begingroup$ Oh yes, this one. Thanks! $\endgroup$
    – user57467
    Sep 7, 2020 at 13:26

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.