Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Testing the Head of List Elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25236] Re: [mg25200] Testing the Head of List Elements
  • From: BobHanlon at aol.com
  • Date: Sun, 17 Sep 2000 04:47:14 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 9/15/2000 2:47:58 AM, mgb_news at hotmail.com writes:

>I am looking for a clever way to select elements from a list based on their
>type (Head).  Specifically, I want to extract all the elements of type
>dtring from a list of elements of different types (string, number,
>character, etc.).
>

Here are some examples

testList = {1, 2, "three", 4, "five", x, y, Pi, 3 + 2I};
Cases[testList, _String]
Cases[testList, _Symbol]
Cases[testList, _Symbol?(! NumericQ[#] &)]
Cases[testList, _Symbol?NumericQ]
Cases[testList, _?NumberQ]
Cases[testList, _?NumericQ]
Cases[testList, _Complex]
Select[testList, Im[#] == 0 &]
Cases[testList, _Integer]
Select[testList, Element[#, Reals] &]

There is an equivalent Select statement for every Cases statement and vice 
versa.


Bob Hanlon


  • Prev by Date: Re: how to compile?
  • Next by Date: Re: Testing the Head of List Elements
  • Previous by thread: Re: Testing the Head of List Elements
  • Next by thread: Re: Testing the Head of List Elements