Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Re: rule based program for "Deleting repeated members of a list."

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81967] Re: [mg81938] Re: rule based program for "Deleting repeated members of a list."
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Mon, 8 Oct 2007 00:00:10 -0400 (EDT)
  • References: <fe7j44$qga$1@smc.vnet.net> <8456040.1191774819207.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Split[s][[All,1]] will be faster (for huge lists) than First/@Spit[s].

Bobby

On Sun, 07 Oct 2007 04:30:44 -0500, Szabolcs Horvát <szhorvat at gmail.com>  
wrote:

> 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.
>
> Why do you insist on a "rule-based" solution?
>
> The obvious (and efficient) solution is
> First /@ Split[s]
>
> An inefficient replacement-rule-based solution is
> s //. {be___, x_, x_, en___} -> {be, x, en}
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Play rests using Mathematica MIDI
  • Next by Date: Dashing[] problem with eps -> pdf -> printer
  • Previous by thread: Re: rule based program for "Deleting repeated members of a list."
  • Next by thread: Re: rule based program for "Deleting repeated members of a list."