MathGroup Archive 2002

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

Search the Archive

Re: Keeping order with Union


Dave Snead <dsnead6 at charter.net> wrote:

> 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?

Here is one way using pattern-matching:

   {a, b, c, d, a, 1, 2, 1, 3, x, a, b, c} //. 
      {a___, x_, b___, x_, c___} :> {a, x, b, c}

Cheers,
   Paul

-- 
____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: RE: dropping higher order terms
  • Next by Date: Re: TeXForm and negative exponents
  • Previous by thread: Re: help: recursive functions
  • Next by thread: Re: Re: Keeping order with Union