Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg64854] Re: [mg64849] Extract values and multilpicities from list
  • From: gardyloo <gardyloo at mail.wsu.edu>
  • Date: Mon, 6 Mar 2006 05:00:50 -0500 (EST)
  • References: <200603050819.DAA09793@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I assume that the algorithms would vary in timings both because of the 
list length, and because of the multiplicities. If I produce a list of 
only zeros, or just ones and twos, the algorithms may be much faster in 
those cases than with, for example, a list of length 1000, containing 
1000 different machine-precision reals.
   Despite the difficulty of quantifying "shortest", here's a possibility:

With[{elems = lstIn // Union}, Transpose[{elems, Count[lstIn, #] & /@ elems}]]


           Cheers!

                 C.O.


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: 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