Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg77466] Re: Selecting Sub-lists After Split
  • From: Bill Rowe <readnewsciv at>
  • Date: Sat, 9 Jun 2007 05:38:12 -0400 (EDT)

On 6/8/07 at 5:34 AM, gregory.lypny at (Gregory Lypny)

>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

A simple way to do this would be to use pattern matching and Cases.

=46irst generate so data

In[12]:= data = Split[RandomReal[{-1, 1}, 20], #1 #2 > 0 &]

Out[12]= {{0.515309},{-0.014795},{0.329838,0.896598},{-0.414435,

then to pick out the sub-lists with negative values

In[13]:= Cases[data, {_?(# < 0 &), ___}]

Out[13]= {{-0.014795},{-0.414435,-0.326671,-0.347789,-0.627698,
To reply via email subtract one hundred and four

  • Prev by Date: Re: Re: v6: still no multiple undo?
  • Next by Date: Re: Unable to copy graphics from Mathematica 6 to Publicon
  • Previous by thread: Re: Selecting Sub-lists After Split
  • Next by thread: Re: Selecting Sub-lists After Split