WLJS LogoWLJS Notebook

Split

Split[list] splits list into sublists consisting of runs of identical elements.

Split[list, test] treats adjacent elements as identical when test yields True.

Examples

Split into runs:

Split[{1, 1, 2, 3, 3, 3, 1}]
(* {{1, 1}, {2}, {3, 3, 3}, {1}} *)

With custom test:

Split[{1, 2, 3, 5, 6, 8}, #2 == #1 + 1 &]
(* {{1, 2, 3}, {5, 6}, {8}} *)

Please visit the official Wolfram Language Reference for more details.

On this page