RE: Extracting Terms From a List
- To: mathgroup at smc.vnet.net
- Subject: [mg44203] RE: [mg44183] Extracting Terms From a List
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 26 Oct 2003 00:41:57 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Bruce,
You almost got it. All you have to do is add a level specification as a last
argument to the Cases statement.
Cases[{3, Sqrt[2], (x + y)^2, x + y^2}, _Integer | _^2, Infinity]
{3, 2, 2, (x + y)^2, 2, y^2}
Without the level specification, Mathematica only looks at the first level
of the expression.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Bruce W. Colletti [mailto:bcolletti at compuserve.com]
To: mathgroup at smc.vnet.net
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} .
Thankx.
Bruce