Re: Testing the Head of List Elements
- To: mathgroup at smc.vnet.net
- Subject: [mg25240] Re: Testing the Head of List Elements
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 17 Sep 2000 04:47:18 -0400 (EDT)
- References: <8psf4k$9n1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Marshall, Cases[{"str", 1, -2, 1.2, 1 + 2 I, 2/3, A, aB, AA}, _Complex] {1 + 2 \[ImaginaryI]} Try the following in place of _Complex. _String, _Integer, _Real, _Rational, _Symbol Also we can use builtin tests, Positive, Negative or NonNegative and those ending in Q. Please look these up individually on in the Help Browser. ?*Q ArgumentCountQ MatrixQ AtomQ MemberQ DigitQ NameQ EllipticNomeQ NumberQ EvenQ NumericQ ExactNumberQ OddQ FreeQ OptionQ HypergeometricPFQ OrderedQ InexactNumberQ PartitionsQ IntegerQ PolynomialQ IntervalMemberQ PrimeQ InverseEllipticNomeQ SameQ LegendreQ StringMatchQ LetterQ StringQ LinkConnectedQ SyntaxQ LinkReadyQ TrueQ ListQ UnsameQ LowerCaseQ UpperCaseQ MachineNumberQ ValueQ MatchLocalNameQ VectorQ MatchQ Cases[{"str", "a", 1, -2, Pi, 1.2, 1 + 2 I, 2/3, A, aB, AA}, _?NumericQ] \!\({1, \(-2\), 1.2`, 1 + 2\ \[ImaginaryI], 2\/3}\) For characters we can use Cases[{"str", "a", 1, -2, Pi, 1.2, 1 + 2 I, 2/3, A, aB, AA}, x_String /; StringLength[x] == 1] {"a"} -- 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 "Marshall Bartlett" <mgb_news at hotmail.com> wrote in message news:8psf4k$9n1 at smc.vnet.net... > I'm something of a newbie with Mathematica; please excuse my ignorance. > > 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.). > > Any suggestions? > > -- > -------------------------------------------------------------- > Marshall Bartlett > Department of Geology and Geophysics > University of Utah > mgb_news at hotmail.com > -------------------------------------------------------------- > > >