Re: Extracting Terms From a List
- To: mathgroup at smc.vnet.net
- Subject: [mg44199] Re: Extracting Terms From a List
- From: bobhanlon at aol.com (Bob Hanlon)
- Date: Sun, 26 Oct 2003 00:41:53 -0400 (EDT)
- References: <bndkar$g5s$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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>