Re: rule based program for "Deleting repeated members of a list."
- To: mathgroup at smc.vnet.net
- Subject: [mg81959] Re: rule based program for "Deleting repeated members of a list."
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sun, 7 Oct 2007 05:41:48 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fe7j44$qga$1@smc.vnet.net>
mumat wrote: > Hi, > > I have a list s={a,b,c,c,d,e,e,f,g,g,g,h,a,b}; > > I need to write a program so that it reads the list and ignors > repeated elements; so it outputs the following: > > RepeatRemover[s]={a,b,c,d,e,f,g,h,a,b}; > > I am looking for a rule-based program to do this! > > Any help would be greatly appreciated. In[1]:= s = {a, b, c, c, d, e, e, f, g, g, g, h, a, b}; In[2]:= Union /@ Split[s] // Flatten Out[2]= {a, b, c, d, e, f, g, h, a, b} In[3]:= s //. {a___, b_, b_, c___} -> {a, b, c} Out[3]= {a, b, c, d, e, f, g, h, a, b} Regards, -- Jean-Marc