TakeDrop is nice because after taking a subarray, it also returns the remaining subarray. But it is limited in that the part specification can only be ranges, and not specific elements.

For example, TakeDrop[{a, b, c, d}, {1, 3}] yields {{a, b, c}, {d}}, but it is not possible to do something like TakeDrop[{a, b, c, d}, {{1}, {3}}] to get {{a, c}, {b, d}}.

The obvious needed generalization would be named something like PartDelete, but I cannot find it. Is there such a function?

  • 7
    $\begingroup$ Like Through[{Extract, Delete}[{a, b, c, d}, {{1}, {3}}]]? I don't think there's a built-in, but as you can see it's not too hard to do. (FWIW, I still do Through[{Take, Drop}[(* stuff *)]] out of habit.) $\endgroup$ – J. M.'s technical difficulties Apr 9 '18 at 16:14

As J.M. mentioned in the comments, Through[{Extract, Delete}] does the job:

Through[{Extract, Delete}[{a, b, c, d}, {{1}, {3}}]]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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