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 > > >
- References:
- Extract values and multilpicities from list
- From: "Dr. Wolfgang Hintze" <weh@snafu.de>
- Extract values and multilpicities from list