Re: How to select unique elements in a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg8348] Re: How to select unique elements in a list?
- From: "Nigel King" <nigelk at nortel.ca>
- Date: Tue, 26 Aug 1997 02:22:42 -0400
- Organization: Nortel
- Sender: owner-wri-mathgroup at wolfram.com
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