MathGroup Archive 2010

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

Search the Archive

Re: List of multiple elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112055] Re: List of multiple elements
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 27 Aug 2010 04:08:01 -0400 (EDT)
  • References: <i55gq0$2cu$1@smc.vnet.net>

On Aug 26, 3:48 am, "Dr. Wolfgang Hintze" <w... at snafu.de> wrote:
> Given the list
>
> a={1,1,2,1,2};
>
> we can reduce multiple instances of elements using
>
> b=Union[a]
> {1,2}
>
> The question is now how to compute the list of multiple elements.
> In our example this would be m={1,1,2}.
>
> A possible solution is
>
> m[x_]:= Flatten[Take[#, {1, Length[#] - 1}] & /@ Select[Split[x],
> Length[#] > 1 &]]
>
> m[a]
> {1,1,2}
>
> I'm sure there is a much more elegant solution. Can you suggest one?
>
> Remark
>
> m[a] can be viewed as a kind of difference: m[a] = a "MINUS" Union[a]
> Inverting gives the "SUM": a = m[a] "PLUS" Union[a] =
> Join[m[a],Union[a]]
>
> Regards,
> Wolfgang

See Bill White's "DuplicateElements" from Oct 2005:

http://groups.google.ca/group/comp.soft-sys.math.mathematica/msg/02c640176775e2e1

It deletes the initial instance of every value. All instances after
the first are kept, in the order in which they come.


  • Prev by Date: Re: List of multiple elements
  • Next by Date: Problems with Module
  • Previous by thread: Re: List of multiple elements
  • Next by thread: Re: List of multiple elements