MathGroup Archive 2007

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

Search the Archive

Re: split

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73631] Re: [mg73572] split
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 23 Feb 2007 04:40:51 -0500 (EST)
  • References: <200702220930.EAA24214@smc.vnet.net>

On 22 Feb 2007, at 10:30, Arkadiusz.Majka at gmail.com wrote:

> 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
>
>


Just look at the documentation for Split:


?Split
Split[list] splits list into sublists consisting of runs of
identical elements. Split[list, test] treats pairs of adjacent 
elements as
identical whenever applying the function test to them yields True.

Which tells you that one (out of many) ways to do this is:

In[90]:=
Split[z,(#1-3)*(#2-3)=B30&]

Out[90]=
{{1,3,2},{6,4,7,5},{1},{7}}

Andrzej Kozlowski=


  • References:
    • split
      • From: Arkadiusz.Majka@gmail.com
  • Prev by Date: Re: Showing that ArcSinh[2]/ArcCsch[2] is 3?
  • Next by Date: Re: Maclaurin series for ArcCosh[x]
  • Previous by thread: Re: split
  • Next by thread: Re: split