Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

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

Search the Archive

Re: How to do a negative pattern?

  • To: mathgroup at
  • Subject: [mg90579] Re: How to do a negative pattern?
  • From: Bill Rowe <readnews at>
  • Date: Mon, 14 Jul 2008 05:22:09 -0400 (EDT)

On 7/13/08 at 3:47 PM, stevensiew2 at (Steven Siew) wrote:

>I have used the function DeleteCases which has the format


>However what I wanted is a negative pattern like


>But I have no idea how to craft a negative pattern. Alternatively I
>suppose I could do with a DeleteCasesNot function. Something like

>In[3]:= mylist={ {1,1},{1,2},{1,3},{2,1},{2,2},{2,3} }

>In[5]:= myselectionB = DeleteCasesNot[mylist,{_,3}]

>Out[5]= {{1, 3}, {2, 3}}

>Does anyone has any idea how I could code up a DeleteCasesNot

You can achieve what you want using DeleteCases with the
appropriate pattern, i.e.,

In[2]:= DeleteCases[mylist, {_, _?(# != 3 &)}]

Out[2]= {{1, 3}, {2, 3}}

But note deleting all cases that do not match a given pattern is
the same as keeping all cases that do match the pattern. So, the
same result can be achieved with

In[3]:= Cases[mylist, {_, 3}]

Out[3]= {{1, 3}, {2, 3}}

  • Prev by Date: Re: If and symbol creation
  • Next by Date: Re: What does FullForm[ ] actually do?
  • Previous by thread: Re: How to do a negative pattern?
  • Next by thread: Re: How to do a negative pattern?