Re: Keeping order with Union

• To: mathgroup at smc.vnet.net
• Subject: [mg32627] Re: Keeping order with Union
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Fri, 1 Feb 2002 02:02:29 -0500 (EST)
• Organization: University of Western Australia
• References: <a38bd0\$2n\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

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