Re: Extracting a sub-list?
- To: mathgroup at smc.vnet.net
- Subject: [mg37958] Re: Extracting a sub-list?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 22 Nov 2002 04:16:06 -0500 (EST)
- References: <arg52u$6bd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> How do I extract the subset of answers in a list that are pure integers?
Several ways:
lst = Table[x/2, {x, 1, 5}]
{1/2, 1, 3/2, 2, 5/2}
Select[lst, IntegerQ]
{1, 2}
Cases[lst, _Integer]
{1, 2}
Cases[lst, _?IntegerQ]
{1, 2}
Cases[lst, x_ /; IntegerQ[x]]
{1, 2}
Information on these techniques is available in the Help Browser under
Select,Cases,Condition,PatternTest
Also note DeleteCases.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"AngleWyrm" <no_spam_anglewyrm at hotmail.com> wrote in message
news:arg52u$6bd$1 at smc.vnet.net...
> How do I extract the subset of answers in a list that are pure integers?
> As an example,
>
> in:
> Table[x/2, {x, 1, 5}]
> IntegerQ /@ %
>
> out:
> { 1/2, 1, 3/2, 2, 5/2 }
> { False, True, False, True, False }
>
> But I want to get a result of:
> { 1, 2 }
>
> -:¦:-
> AngleWyrm
>
>