MathGroup Archive 2007

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

Search the Archive

Re: split

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73598] Re: split
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 23 Feb 2007 04:22:59 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <erjo7l$nrf$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

the test in Split[] has *two* arguments to
compare *two* adjacent elements and

Split[z,#1=E2=89=A43 && #2=E2=89=A43&]

gives

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

but the elements >3 are not grouped together. This can be done
with

Split[z, #1
     =E2=89=A4 3 && #2 =E2=89=A4 3 &] //. {a___, {b__}, {c_},
        d___} /; Last[{b}] > 3 && c > 3 :> {a, {b, c}, d}

and one gets

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

Regards
   Jens

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


  • Prev by Date: Re: split
  • Next by Date: Re: split
  • Previous by thread: Re: split
  • Next by thread: Re: split