MathGroup Archive 2003

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

Search the Archive

Re: Extracting Terms From a List


lst = {3,Sqrt[2],(x+y)^2,x+y^2};

Use the optional levelspec parameter (see on-line help for Cases)

Cases[lst,_Integer|_^2,2]

{3, 2, 2, (x + y)^2, y^2}

However, the result that you specified requires different levelspecs for the
different patterns

Join[Cases[lst,_Integer],Cases[lst,_^2,2]]

{3, (x + y)^2, y^2}


Bob Hanlon

In article <bndkar$g5s$1 at smc.vnet.net>, "Bruce W. Colletti"
<bcolletti at compuserve.com> wrote:

<< How would I cull integers and squared terms from {3, Sqrt[2], (x+y)^2,
x+y^2}?   The desired output is {3, (x+y)^2, y^2}.  Unfortunately:

Cases[{3, Sqrt[2], (x+y)^2, x+y^2}, _Integer | _^2]

returns {3, (x+y)^2} .
 >><BR><BR>


  • Prev by Date: Re: Extracting Terms From a List
  • Next by Date: RE: Extracting Terms From a List
  • Previous by thread: Re: Extracting Terms From a List
  • Next by thread: RE: Extracting Terms From a List