MathGroup Archive 2002

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

Search the Archive

Re: Re: Keeping order with Union

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32642] Re: [mg32605] Re: [mg32590] Keeping order with Union
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 1 Feb 2002 02:02:59 -0500 (EST)
  • References: <200201310645.BAA04317@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

The problem with ReplaceRepeated is that when the list is long it will take
forever to accomplish the task (process time is not linear wrt list length).
I used your elimDupes on a list of 100,000 characters and had to abort it
after one and a half hours (the same problem took less than 1 second with
Carl Woll's routine, and less than three seconds with the one I proposed
yesterday in message [mg32612]). The problem may be circumvented by breaking
down the long list into small sublists (100 - 150 elements each), applying
the function to each of them, merging the results, and repeating this again
and again. This approach may not be efficient in the present problem, but
has proved useful in other cases where the pattern-matching method provides
a straightforward solution.

Tomas Garza
Mexico City

----- Original Message -----
From: <BobHanlon at aol.com>
To: mathgroup at smc.vnet.net
Subject: [mg32642] [mg32605] Re: [mg32590] Keeping order with Union


>
> In a message dated 1/30/02 4:26:36 AM, dsnead6 at charter.net writes:
>
> >I'd like a function that throws out duplicate entries in a list and keeps
> >the
> >original list order.  (when it sees 2 equal entries it throws out the one
> >that is later in the list).   I'd use Union, but it sometimes changes the
> >order of the elements in the list.  What's the tersest way to do this?
> >
>
> elimDupes[x_List] :=
>
>     (x//.{s___,e_,i___,e_,f___} :>{s,e,i,f});
>
> origList = {b,b,c,a,c,a,b,d};
>
> Union[origList]
>
> {a, b, c, d}
>
> elimDupes[origList]
>
> {b, c, a, d}
>
>
> Bob Hanlon
> Chantilly, VA  USA
>



  • Prev by Date: Re: help: recursive functions
  • Next by Date: Re: Gross Bug in Simplify
  • Previous by thread: Re: Keeping order with Union
  • Next by thread: Re: Keeping order with Union