Re: Re: How to select unique elements in a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg8416] Re: [mg8348] Re: How to select unique elements in a list?
- From: jpk at max.mpae.gwdg.de
- Date: Sat, 30 Aug 1997 00:42:23 -0400
- Sender: owner-wri-mathgroup at wolfram.com
> From nigelk at nortel.ca Tue Aug 26 15:10:46 1997
> Date: Tue, 26 Aug 1997 02:22:42 -0400
> From: "Nigel King" <nigelk at nortel.ca>
> Subject: [mg8348] Re: How to select unique elements in a list?
>
> In article <5rmq5u$po1 at smc.vnet.net>,
> crose at c2.telstra-mm.net.au (Colin Rose) wrote:
>
> >"Carl Woll" <carlw at u.washington.edu> wrote:
> >
> > First, let me say that Union does not do what I'm looking for! I am
> > interested in a function which returns the unique elements from a list.
> > Let's call the function Distinct. Then, I want
> >
> > Distinct[{i1,i2,i3,i2}] to return {i1,i3}
> >
> > RemoveDuplicates[a___,i_,i_,b___]:=RemoveDuplicates[a,b]
> > Distinct[a_List]:=List@@RemoveDuplicates@@Sort[a]
>
> I am not sure that people have noticed in this that the removal above does
> not remove odd numbers of duplicates
>
> In[19]:=Distinct[{1,2,2,2,3}]
> Out[19]={1,2,3}
>
> any solutions? As noticed pattern matching is not easy!
>
> Nigel King
> Northern Telecom
>
>
>
Yes,
what is with
RemoveDuplicates[{a___,i_,i_,b___}] :=
RemoveDuplicates[{a,b} /. i-> Sequence[]]
Distinct[a_List]:=RemoveDuplicates[Sort[a]]
Hope that helps
Jens