MathGroup Archive 2006

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

Search the Archive

Re: Extract values and multilpicities from list


Dr. Wolfgang Hintze schrieb:
> 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
> 
straightforward:

lstOut = {First@#, Length@#} & /@ Split@Sort[lstIn]
-->{{1, 2}, {2, 2}, {3, 1}, {4, 3}, {5, 1}}


  • Prev by Date: Re: Extract values and multilpicities from list
  • Next by Date: Re: Extract values and multilpicities from list
  • Previous by thread: Re: Extract values and multilpicities from list
  • Next by thread: Re: Extract values and multilpicities from list