Run-Length Encoding

A specification of elements in a list as a list of pairs giving the element and number of times it occurs in a run. For example, given the list {1,1,1,3,3,6,6,6,2,2,2,2,3,3,1,4,4}, the run-length encoding is {{1,3}, {3,2}, {6,3}, {2,4}, {3,2}, {1,1}, {4,2}}. Run-length encoding can be implemented in the Wolfram Language as:

  RunLengthEncode[x_List] :=
    {First[#], Length[#]}& /@ Split[x]

See also

Look and Say Sequence, Run

Explore with Wolfram|Alpha

Cite this as:

Weisstein, Eric W. "Run-Length Encoding." From MathWorld--A Wolfram Web Resource.

Subject classifications