MathGroup Archive 2004

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

Search the Archive

RE : DeleteCases : several at once, conditions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49378] RE : [mg49369] DeleteCases : several at once, conditions
  • From: "Florian Jaccard" <florian.jaccard at eiaj.ch>
  • Date: Sat, 17 Jul 2004 06:38:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

liste = {{1, 6, 
    7}, {3, 6, 9}, {1, 2, 11}, {3, 5, 9}, {2, 5, 6}, {2, 9, 11}, {2, 10, 
      11}, {3, 7, 9}, {5, 8, 11}, {3, 7, 9}, {7, 8, 9}, {2, 5, 12}, {2, 6, 
      10}, {2, 10, 11}, {1, 6, 9}, {6, 10, 12}, {3, 6, 12}, {2, 5, 12}, {3,
8,
       9}, {9, 3, 4}, {1, 2, 7}};

if you want to delete all cases matching {1,_,_} or {9,_,_} :

In[16]:=
DeleteCases[liste, a_ /; MatchQ[a, {9, _, _}] || MatchQ[a, {1, _, _}]]

Out[16]=
{{3, 6, 9}, {3, 5, 9}, {2, 5, 6}, {2, 9, 11}, {2, 10, 11}, {3, 7, 9}, 
  {5, 8, 11}, {3, 7, 9}, {7, 8, 9}, {2, 5, 12}, {2, 6, 10}, 
  {2, 10, 11}, {6, 10, 12}, {3, 6, 12}, {2, 5, 12}, {3, 8, 9}}

if you want to delete all cases where the first element is even :

In[17]:=
DeleteCases[liste, a_ /; EvenQ[First[a]]]

Out[17]=
{{1, 6, 7}, {3, 6, 9}, {1, 2, 11}, {3, 5, 9}, {3, 7, 9}, {5, 8, 11}, 
  {3, 7, 9}, {7, 8, 9}, {1, 6, 9}, {3, 6, 12}, {3, 8, 9}, {9, 3, 4}, 
  {1, 2, 7}}

If you want to delete all cases where one element (or 2 ore 3) is even :

In[28]:=
DeleteCases[liste, a_ /; Or @@ EvenQ /@ a]

Out[28]=
{{3, 5, 9}, {3, 7, 9}, {3, 7, 9}}

ans so on...

regards
 
F.Jaccard

-----Message d'origine-----
De : camerzone [mailto:camerzone at yahoo.com] 
Envoyé : vendredi, 16. juillet 2004 12:07
À : mathgroup at smc.vnet.net
Objet : [mg49369] DeleteCases : several at once, conditions

Suppose you have a list of lists, something like
{{1, 6, 7}, {3, 6, 9}, {1, 2, 11}, {3, 5, 9}, {2, 5, 6}, {2, 9, 11}, {
  2, 10, 11}, {3, 7, 9}, {5, 8, 11}, {3, 7, 9}, {7, 8, 9}, {2, 5, 12},
{2, 6,
    10}, {2, 10, 11}, {1, 6, 9}, {6, 10, 12}, {3, 6, 12}, {2, 5, 12},
{3, 8,
     9}, {1, 2, 7}}
and you want to delete cases matching several different patterns, say
{1,_,_} and {9,_,_}
What's the most efficient way?

Also, can you use conditions with DeleteCases?  Say, I want to delete
all cases containing even numbers?

tks




  • Prev by Date: RE: DeleteCases : several at once, conditions
  • Next by Date: Re: importing image and getting numbers from the gray intensity
  • Previous by thread: RE : How to extract a solution from Mathematica's answer to "Solve"
  • Next by thread: FindRoot s all