Re: Extracting Terms From a List
- To: mathgroup at smc.vnet.net
- Subject: [mg44193] Re: [mg44183] Extracting Terms From a List
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 26 Oct 2003 00:41:47 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On Saturday, October 25, 2003, at 07:26 PM, Bruce W. Colletti 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} . > > Thankx. > > Bruce > > > Probably you either have to use a rather elaborate pattern or apply Cases twice: Join[Cases[{3, Sqrt[2], (x + y)^2, x + y^2}, _Integer], Cases[{3, Sqrt[2], (x + y)^2, x + y^2}, _^2, {1, 2}]] {3, (x + y)^2, y^2} Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/