1

I have a list of elements, for example:

myList={5, 12, 16, 18, 19, 24, 28, 29, 31, 32, 35, 42, 43, 47, 50, 53, 60, 61, 62, 64, 79, 82, 84, 92, 105, 128, 136, 153, 154, 155, 156, 158, 159, 160, 164}

I wish to create sublists based on consecutive elements and drop sublists that have a length of 1:

{{18,19},{28,29},{31,32},{42,43},{60,61,62},{153,154,155,156},{158,159,160}}

I can't work out a simple method to do this, but thought there must be a way with Differences, SplitBy, Partition, Cases, etc. or am I missing something obvious?

Thank you in advance!

Jim
  • 43
  • 5
  • Its been asked before here: http://mathematica.stackexchange.com/questions/23607/find-continuous-sequences-inside-a-list

    You want Split

    – Quantum_Oli Feb 02 '16 at 21:04

1 Answers1

3
Select[Split[myList, #2 - #1 == 1 &], Length[#] > 1 &]
Quantum_Oli
  • 7,964
  • 2
  • 21
  • 43