# How can I drop elements in certain positions from a list using Drop?

a = Table[i, {i, 1, 10}]
Drop[a, {5, 8}]


If go with the above procedure, it will delete all the elements from between position 5 to 8. How can I drop elements which are at position 5 and position 8 using Drop?

Use instead Delete, in this way:

a = Table[i, {i, 1, 10}];
Delete[a, {{5}, {8}}]


(*

{1, 2, 3, 4, 6, 7, 9, 10}

*)

By the way, you can be far more efficient:

a = Range[10]

• can we give the list of position which I wanted to drop like {3,5,8,9} Nov 29, 2018 at 7:49
• Delete[a,{{3},{5},{8},{9}}] Nov 29, 2018 at 7:50
• Also Delete[a, Partition[{3, 5, 8, 9}, 1]] comes to mind... if the list of positions gets longer. Nov 29, 2018 at 8:04
• In general, you can use Delete[a, List/@{3, 5, 8, 9}]. Jan 28 at 21:15
Drop[a, {5, 8, 3}]


{1, 2, 3, 4, 6, 7, 9, 10}

Fold[Drop[#, {#2}] &, a, Reverse[{5, 8}]]


{1, 2, 3, 4, 6, 7, 9, 10}

list = Range[10];

p = {5, 8};


Using SubsetReplace (new in 12.1)

SubsetReplace[list, p :> Nothing]


{1, 2, 3, 4, 6, 7, 9, 10}

list = Range[10];


Using SequenceCases:

p = {5, 8};

SequenceCases[list, s : {Except[Alternatives @@ p]} :> Splice@s]

(*{1, 2, 3, 4, 6, 7, 9, 10}*)