SplitBy

SplitBy[list, f]
splits list into sublists consisting of runs of successive elements that give the same value when f is applied.

SplitBy[list, {f1, f2, ...}]
recursively splits list into sublists by testing elements successively with each of the .

DetailsDetails

  • SplitBy[list, ...] splits but does not rearrange list.
  • SplitBy performs comparisons only on adjacent pairs of elements.
  • SplitBy[list] is equivalent to SplitBy[list, Identity], which is also equivalent to Split[list].
  • SplitBy[list, {f1, f2}] is equivalent to Map[SplitBy[#, f2]&, SplitBy[list, f1]].

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Split into runs of numbers with identical integer part:

In[1]:=
Click for copyable input
Out[1]=

Split into runs of triples with identical first component:

In[1]:=
Click for copyable input
Out[1]=

Split first by their first component and then by their second:

In[2]:=
Click for copyable input
Out[2]=

Split dates into runs with identical year:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
New in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »