Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Extract values and multilpicities from list

  • To: mathgroup at
  • Subject: [mg65053] Re: Extract values and multilpicities from list
  • From: "Dr. Wolfgang Hintze" <weh at>
  • Date: Sun, 12 Mar 2006 23:59:14 -0500 (EST)
  • References: <due96k$ach$>
  • Sender: owner-wri-mathgroup at

Thanks to everybody in the group who sent replies to my question.
Amazing number, and variety as well!

Here is an overview over the different types of solution proposals

1) Type Union-Count (3 nominations)

2) Type Split-Sort (10 nominations)
This is mainly run-length-encoding which also appears in the Help of mma

3) Type Reap-Sow (1 nomination)

4) Type Frequency (1 nomination)
<< Statistics`DataManipulation`
lstOut = Reverse /@ Frequencies[lstIn]//Timing;

5) Type Sparse-Array (1 nomination)
runs[d_] :=
   SparseArray[Transpose[{d, Range[Length[d]]}] -> Table[1, {Length[d]}]] /.
    SparseArray[_, _, _, {_, {p_, __}, _}] :>
Transpose[{Range[Length[p] - 1], Rest[p] - Most[p]}]

I was not happy with the heading of my formulation of the problem 
(disregarding the little typo ;-)). At first I tended to call it 
something like "histogram problem", now I think that "run-length 
encoding" is the most apropriate.

Best regards,

Dr. Wolfgang Hintze wrote:

> Given a list of integers which may repeat, e.g.
> lstIn = {2,3,4,4,2,1,1,5,4}
> provide a list of different values and their respective multiplicities,
> in the example,
> LstOut= {{1,2},{2,2},{3,1},{4,3},{5,1}}
> Who finds the shortest function doing this task in general?
> Thanks.
> Best regards,
> Wolfgang

  • Prev by Date: Re: 3D-plot over a triangle
  • Next by Date: Re: Graphics3D polygon face colors
  • Previous by thread: Re: Extract values and multilpicities from list
  • Next by thread: Mathematica Link for Excel