# List of deleted items from using Delete

partstodelete = {{1, 2}, {1, 5}, {1, 6}.. {2, 21}, {2, 28}, {2, 35}..};


Delete[data, partstodelete] deletes parts partstodelete from data.

How do I just get a list of the parts (i.e what is deleted; or the complement of data and Delete[data, partstodelete]).

Seems like it should be straightforward using Part, but data[[partstodelete]] does not work (Part doesn't seem to allow depth of part specifications if giving it a list?)

## 2 Answers

data = Array[a, {3, 10}];

partstodelete = {{1, 2}, {1, 5}, {1, 6}, {2, 3}, {2, 5}, {2, 8}};

data2 = Delete[data, partstodelete];


Using Part, the values deleted are

data[[##]] & @@@ partstodelete

(* {a[1, 2], a[1, 5], a[1, 6], a[2, 3], a[2, 5], a[2, 8]} *)


You can define a function that returns (similar to TakeDrop) both the kept and the deleted parts of input list using Through + Delete + Extract:

ClearAll[deleteExtract]
deleteExtract = Through[{ Delete, Extract} @ ##] &;

data = Array[a, {3, 7}];
partstodelete = {{1, 2}, {1, 5}, {1, 6}, {2, 3}, {2, 5}};

MapAt[Framed, data, partstodelete] // TableForm


{kept, deleted} = deleteExtract[data, partstodelete];

kept

 {{a[1, 1], a[1, 3], a[1, 4], a[1, 7]},
{a[2, 1], a[2, 2], a[2, 4], a[2, 6], a[2, 7]},
{a[3, 1], a[3, 2], a[3, 3], a[3, 4], a[3, 5], a[3, 6], a[3, 7]}}

deleted

{a[1, 2], a[1, 5], a[1, 6], a[2, 3], a[2, 5]}

data /. { x : Alternatives @@ (Join @@ kept) :> Highlighted[x],
x : Alternatives @@ deleted :>  Highlighted[x, Background -> Pink]} // TableForm