Skip to main content
5 of 5
edited body
brienna
  • 1.1k
  • 5
  • 13

How to split list into segments based on first element of sublist, and remove ineligible segments

I have a list that looks like this:

{{1., 1812.}, {2., 10076.}, {3., 4762.}, {1., 4262.}, {2., 
  5059.}, {3., 5860.}, {1., 1272.}, {2., 18933.}, {3., 67205.}, {1., 
  3859.}, {2., 7429.}, {1., 4048.}, {2., 14393.}, {3., 10493.}, {1., 
  3961.}, {2., 8083.}, {3., 7971.}, {1., 7739.}, {2., 15620.}, {3., 
  16718.}, {1., 3173.}, {2., 22983.}, {3., 17953.}, {1., 1201.}, {2., 
  3787.}, {3., 3142.}, {1., 6856.}, {2., 12660.}, {3., 17041.}, {1., 
  11860.}, {2., 13483.}, {3., 14537.}, {1., 1324.}, {2., 4267.}, {3., 
  8876.}, {1., 3457.}, {2., 21622.}, {3., 18678.}, {1., 5038.}, {2., 
  14656.}, {3., 10739.}, {1., 18731.}, {2., 59627.}, {3., 
  50827.}, {1., 4624.}, {2., 13460.}, {3., 34597.}, {1., 6527.}, {2., 
  11325.}, {3., 8654.}, {1., 4971.}, {2., 38390.}, {3., 14953.}, {1., 
  4936.}, {2., 24187.}, {3., 46497.}, {1., 2371.}, {2., 2872.}, {3., 
  3335.}, {1., 3750.}, {2., 3927.}, {3., 3251.}, {1., 5660.}, {2., 
  6535.}, {3., 8942.}, {1., 2451.}, {2., 9891.}, {3., 8351.}, {1., 
  6293.}, {2., 6983.}, {3., 6522.}, {1., 4577.}, {2., 20683.}, {3., 
  17143.}, {1., 2005.}, {2., 3216.}, {3., 3593.}, {1., 1428.}, {2., 
  2790.}, {3., 3786.}, {1., 6300.}, {2., 24462.}, {3., 23045.}, {1., 
  1145.}, {2., 10199.}, {3., 5754.}, {1., 2797.}, {2., 5418.}, {3., 
  5623.}, {1., 3096.}, {2., 4565.}, {3., 4620.}, {1., 3249.}, {2., 
  5021.}, {3., 4740.}, {1., 2323.}, {2., 2481.}, {3., 4890.}, {1., 
  4063.}, {2., 5133.}, {3., 6590.}, {1., 3751.}, {2., 5661.}, {3., 
  10465.}, {1., 4430.}, {2., 9080.}, {3., 6743.}, {1., 2228.}, {2., 
  3626.}, {3., 4979.}, {1., 2141.}, {2., 2885.}, {3., 6303.}, {1., 
  881.87}, {2., 15755.}, {3., 15828.}, {1., 6139.}, {2., 8440.}, {3., 
  7451.}, {1., 5055.}, {2., 7742.}, {3., 8809.}, {1., 1821.}, {2., 
  4326.}, {3., 3964.}, {1., 64625.}, {2., 52030.}, {3., 63770.}, {1., 
  6462.}, {2., 44977.}, {3., 36841.}, {1., 3415.}, {2., 25995.}, {3., 
  15528.}, {1., 5792.}, {2., 7563.}, {3., 7869.}, {1., 2384.}, {2., 
  6246.}, {3., 5707.}, {1., 2505.}, {1., 2193.}, {2., 2374.}, {3., 
  4157.}, {1., 2934.}, {2., 7203.}, {3., 7306.}, {1., 5664.}, {2., 
  24487.}, {3., 13539.}, {1., 10404.}, {2., 10633.}, {3., 
  15397.}, {3., 7417.}, {1., 3382.}, {2., 5394.}, {3., 9266.}, {1., 
  3105.}, {2., 4494.}, {3., 4476.}, {1., 7323.}, {2., 8905.}, {3., 
  9474.}, {1., 9947.}, {2., 16531.}, {3., 17693.}, {1., 6282.}, {2., 
  8970.}, {3., 9944.}, {1., 7470.}, {2., 7089.}, {3., 8682.}, {1., 
  18522.}, {2., 17425.}, {3., 17581.}, {1., 3243.}, {2., 10989.}, {3.,
   6694.}, {1., 2813.}, {2., 15435.}, {3., 14067.}, {1., 5574.}, {2., 
  6781.}, {3., 6654.}, {1., 2719.}, {2., 3455.}, {3., 3672.}, {1., 
  7508.}, {2., 9375.}, {3., 9878.}, {1., 3832.}, {2., 4030.}, {3., 
  4400.}, {1., 5858.}, {2., 7811.}, {3., 6963.}, {1., 4174.}, {2., 
  4080.}, {3., 4611.}, {1., 10320.}, {2., 10396.}, {3., 10936.}, {1., 
  3402.}, {2., 4853.}, {3., 30084.}, {1., 10592.}, {2., 16608.}, {3., 
  13896.}}

It is ordered. I need to split this list into 1., 2., 3. segments based on the first element of each sublist, removing any segments that are smaller than that, e.g. 1., 2.. I want to end up with something like this: {{{1., 1812.}, {2., 10076.}, {3., 4762.}}, {{1., 4262.}, {2., 5059.}, {3., 5860.}}}

The idea seems simple... but the other implementations I have tried require the list to be ordered. I can't change this order. Plus I need to remove certain elements in addition to splitting. I've considered partitioning with varying partition size, although I'm not sure how to do it with a conditional, and then looping through the result to remove any sublists that are smaller than a length of 3.

Another idea for partitioning the list is to split it on the 1.'s. I tried this with Split[list, (#2 =!= {1}) &] but it doesn't quite work. I don't have the syntax correct.

brienna
  • 1.1k
  • 5
  • 13