MathGroup Archive 2003

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

Search the Archive

RE: DeleteCases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42233] RE: [mg42224] DeleteCases
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 25 Jun 2003 01:53:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Shawn Kelly [mailto:kellysm at ornl.gov]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, June 24, 2003 7:27 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg42233] [mg42224] DeleteCases
>
>
>I have twos lists I want to compare with one another and 
>delete the cases
>where the elements in list1 match list2.  For example:
>
>list1={21,41,61,71,81}
>list2={71,73,75,77,79,81}
>
>I want the new list3 to read:
>list3={21,41,61}
>
>It seems to me that the following should work:
>list3=DeleteCases[list1,list2]
>
>Any thoughts?
>
>Thanks
>
>Shawn
>
>

In fact it doesn't

In[3]:= DeleteCases[list1, list2]
Out[3]= {21, 41, 61, 71, 81}

but...

In[4]:= Complement[list1, list2]
Out[4]= {21, 41, 61}

...does.

You may use DeleteCases however, after having Help'ed yourself, define the
right pattern:

In[5]:= DeleteCases[list1, Alternatives @@ list2]
Out[5]= {21, 41, 61}

Performace issues notwithstanding, this might be advantageous if you like to
keep the order of list1 (Complement sorts the result):

In[6]:= DeleteCases[Reverse[list1], Alternatives @@ list2]
Out[6]= {61, 41, 21}

--
Hartmut Wolf


  • Prev by Date: format Text in graphics
  • Next by Date: Re: Lie symmetries for PDE's, MathLie, and Mathematica V 4.1
  • Previous by thread: Re: DeleteCases
  • Next by thread: Lie symmetries for PDE's, MathLie, and Mathematica V 4.1