Split

Split[list]

splits list into sublists consisting of runs of identical elements.

Split[list,test]

treats pairs of adjacent elements as identical whenever applying the function test to them yields True.

Details

  • The default function used to test whether elements are identical is SameQ.
  • Split can be used to perform runlength encoding. »

Examples

open allclose all

Basic Examples  (1)

Generalizations & Extensions  (5)

Split in increasing runs of elements:

Decreasing runs of elements:

Split based on first elements:

Split at jumps:

Split so that in each sublist successive elements are not the same:

Split after every occurrence of a:

Split before every occurrence of a:

Applications  (5)

Group together identical elements:

Split by sign:

Only split when there is a change from negative to positive sign (rising edge):

Only split when there is a change from positive to negative sign (falling edge):

Run-length encoding:

Group equivalence classes according to an equivalence function:

Distribution of lengths of runs of 0s or 1s in the first million bits of :

Distribution of lengths of runs of 0s or 1s in one million pseudorandom bits:

Properties & Relations  (1)

Flatten acts an inverse of Split:

Neat Examples  (2)

Find runs of numbers in base 10 that contain the same number of 1s:

Iterated run-length encoding [more info]:

Introduced in 1996
 (3.0)