MathGroup Archive 2008

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

Search the Archive

Re: DeleteCases and multiple patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93964] Re: DeleteCases and multiple patterns
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sun, 30 Nov 2008 06:57:47 -0500 (EST)
  • References: <ggr217$e21$1@smc.vnet.net>

Hi,
> 
> I have, say a list of list. Each element is a list of length 3 i.e.
> 
> myList={{x1,y1,z1},{x2,y2,z2},...{xN,yN,zN}}
> 
> Now, let's say I want to delete from this list the element which have
> x=2 and 3 using DeleteCases.
> This works :
> 
> DeleteCase[myList,{2,_,_}]
> DeleteCases[myList,{3,_,_}]
> 
> but I would like to use
> 
> DeleteCases[myList,{{2,_,_},{3,_,_}}]
> 
> and this does not work...
> 
> How do I combine multiple patterns in DeleteCases ?

I think you can't, but there is no need to do that, since you can
formulate patterns that match more than one case with Alternatives,
or its short form | . So this should do what you want:

DeleteCases[myList,{2,_,_}|{3,_,_}]

or, in this case:

DeleteCases[myList,{2|3,_,_}]

hth,

albert



  • Prev by Date: Re: DeleteCases and multiple patterns
  • Next by Date: Re: DeleteCases and multiple patterns
  • Previous by thread: Re: DeleteCases and multiple patterns
  • Next by thread: Re: DeleteCases and multiple patterns