# How to delete some element after a certain distance [duplicate]

I want to drop 2 continuous elements every 3 elements,such as I have a list:

list = {3, 5, 5, 5, 2, 5, 1, 0, 5, 0, 4};


I want to get

{3, 5, 5, 5, 1, 0, 4}


Any consice method can do this?

R.M's method with suitable modification:

Flatten @ Partition[list, 3, 5, 1, {}]

{3, 5, 5, 5, 1, 0, 4}


Or for recent versions of Mathematica using UpTo

Flatten @ Partition[list, UpTo[3], 5]

• I used Mathematica for almost three years, but it is hard for me to think Partition can easily do this.. – yode Mar 8 '17 at 20:02
• I just observed that using UpTo[3] instead of 3 slows down the solution with a factor 8 / 10. Therefore, for very long lists @rcollyer's solution Pick[list,PadRight[#,Length@list,#]&@UnitStep@Range[2,-2,-1],1] or this variant Pick[list, Clip[Mod[Range[Length[list]], 5], {2,3}], 2] could be considered as well. – Fred Simons Mar 14 '17 at 19:28
• @Fred Interesting observation; thank you. Using variable length output in Partition slows it down to begin with, i.e. {} is slower than doing a PadRight on the original list then trimming after. I cannot remember where this was discussed but a search would probably find it. – Mr.Wizard Mar 15 '17 at 6:34
Flatten[Take[#, UpTo[3]] & /@ Partition[list, 5, 5, 1, {}]]


{3, 5, 5, 5, 1, 0, 4}

• A small variant, for me easier to understand: Flatten[Take[#,UpTo[3]]&/@Partition[list,UpTo[5]]]. – Fred Simons Mar 8 '17 at 18:50
Flatten[Map[list[[# ;; ;; 5]] &, {1, 2, 3}], {2, 1}]


{3, 5, 5, 5, 1, 0, 4}