Re: DeleteCases
- To: mathgroup at smc.vnet.net
- Subject: [mg42245] Re: DeleteCases
- From: "Shawn Kelly" <kellysm at ornl.gov>
- Date: Wed, 25 Jun 2003 01:53:39 -0400 (EDT)
- Organization: Virginia Tech, Blacksburg, Virginia, USA
- References: <bd8o3o$loi$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
To all that have responded, thanks for the help. I have included some of
the solutions to my problem below:
Complement[list1, list2]
or...
In[5]:= DeleteCases[list1, Alternatives @@ list2]
Out[5]= {21, 41, 61}
or...
list3=DeleteCases[list1, _?(MemberQ[list2, #]&)]
list3=Cases[list1, _?(!MemberQ[list2,#]&)]
list3=Select[list1, !MemberQ[list2,#]&]
or...
In[1]:=
Select[list1,Not[MemberQ[list2,#]]&]
Out[1]=
{21,41,61}
or
In[2]:=
DeleteCases[list1,y_/;MemberQ[list2,y]]
Out[2]=
{21,41,61}
"Shawn Kelly" <kellysm at ornl.gov> wrote in message
news:bd8o3o$loi$1 at smc.vnet.net...
> 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
>
>