MathGroup Archive 2007

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

Search the Archive

Re: split

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73702] Re: split
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Sun, 25 Feb 2007 04:32:35 -0500 (EST)

Just another option might be "UnitStep"

rule = UnitStep[3 - #1] == UnitStep[3 - #2] & ; 

which is...

rule = Equal @@ UnitStep[3 - {#1, #2}] & ; 

z = {1, 3, 2, 3, 3, 6, 3, 3, 4, 7, 5, 1, 7}; 

Split[z, rule]

{{1, 3, 2, 3, 3}, {6}, {3, 3}, {4, 7, 5}, {1}, {7}}

-- 
Dana DeLouis
Windows XP & Mathematica 5.2


<Arkadiusz.Majka at gmail.com> wrote in message
news:erjo7l$nrf$1 at smc.vnet.net...
> Hi,
> 
> I want to split a list, say
> 
> z = {1, 3, 2, 6, 4, 7, 5,1,7};
> 
> into sublist of elements that are less or equal 3.
> 
> so I want to obtain
> 
> {{1,3,2},{6,4,7,5},{1},{7}}
> 
> How to do it? Probably by applying Split, but what to put in Test?
> 
> Split[z,#<=3&] gives :
> 
> {{1, 3, 2, 6}, {4}, {7}, {5}, {1, 7}}
> 
> Why 6 was put in first sublist together with 1, 3, and 2 since 6>3 and
> should be together with 4 in the second sublist?
> 
> Thanks,
> Arek



  • Prev by Date: Re: How to manipulate globals in a function?
  • Next by Date: Re: multi-threading on Mac OS X.
  • Previous by thread: Re: split
  • Next by thread: Maclaurin series for ArcCosh[x]