1
$\begingroup$

This question already has an answer here:

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!

$\endgroup$

marked as duplicate by Community Feb 2 '16 at 21:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
$\begingroup$
Select[Split[myList, #2 - #1 == 1 &], Length[#] > 1 &]
$\endgroup$
  • $\begingroup$ Fantastic! Thanks for the quick answer $\endgroup$ – Jim Feb 2 '16 at 21:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.