Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Selecting Sub-lists After Split

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77469] Re: Selecting Sub-lists After Split
  • From: "Drago Ganic" <dganic at vodatel.net>
  • Date: Sat, 9 Jun 2007 05:39:46 -0400 (EDT)
  • References: <f4b89h$3ls$1@smc.vnet.net>

Hi,
I am not sure if I understand you correctly, but I suggest Select/Cases:

myList = {1, -13, 4, 6, -12.3, -14, 10, 100};
Here you can use Select or Cases:
  Select[myList, Negative]
  {-13, -12.3, -14}
  Cases[myList, _?Negative]
  {-13, -12.3, -14}


myNewList = Split[myList, #1 #2 > 0 &]
{{1}, {-13}, {4, 6}, {-12.3, -14}, {10, 100}}


To get the elements you must now use level specification, so Cases is the 
more natural choice:
Cases[myList, _?Negative, 2]
{-13, -12.3, -14}

But, if you want sub-lists you should use:

Select[myNewList, VectorQ[#, Negative] &]
{{-13}, {-12.3, -14}}

Greetings from Croatia,
Drago

"Gregory Lypny" <gregory.lypny at videotron.ca> wrote in message 
news:f4b89h$3ls$1 at smc.vnet.net...
> Hello everyone,
>
> Suppose I have a list of real number called myList.  I split it into
> sub-lists of positive and negative numbers called myNewList by doing
> this (there may be a more elegant way):
>
> myNewList = Split[myList, #1 #2 > 0 &]
>
> Now, how can I select all of the sub-lists of negative numbers from
> myNewList?
>
> Any tips would be most appreciated.
>
> Regards,
>
> Gregory
> 




  • Prev by Date: Re: Hotkeys - redefine
  • Next by Date: Re: Re: Dynamic PlotLabel in Math6?
  • Previous by thread: Re: Selecting Sub-lists After Split
  • Next by thread: documention for the Documentation Center in math6.0