MathGroup Archive 2004

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

Search the Archive

Re: Cases


>-----Original Message-----
>From: Blimbaum, Jerry AA R22 [mailto:jerry.blimbaum at navy.mil]
To: mathgroup at smc.vnet.net
>Sent: Friday, September 03, 2004 9:35 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg50448] [mg50423] Cases
>
>
>
>Given:   x = {a,b,c,d,d};
>
>Applying   Cases[x,d]   gives an output of {a,b,c}......
>
>However, Cases[x,Not[d]] gives as output an empty list  { }... I
>expected   {a,b,c}.....
>
>Why didnt I get that?
>
>This issue came up when using Thread on vectors...and in some cases the
>Thread resulted in 0 == 0  so it's output in the list  was 
>True....and I
>wanted to remove them....
>
>thanks.....jerry blimbaum
>
>

Jerry,

Not[d] ist not the right pattern (or form as referred in Help) to match elements of x which don't match d, instead

In[6]:= Cases[x, d]
Out[6]= {d, d}

In[8]:= Cases[x, _?(Not[MatchQ[#, d]] &)]
Out[8]= {a, b, c}


But for the better way to do it, use DeleteCases:

In[7]:= DeleteCases[x, d]
Out[7]= {a, b, c}


--
Hartmut Wolf


  • Prev by Date: Re: Cases
  • Next by Date: Re: ExpandAll Problem with Rules
  • Previous by thread: Re: Cases
  • Next by thread: definite and indefinite Integrate