MathGroup Archive 2006

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

Search the Archive

Re: question about Split[...]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64557] Re: [mg64529] question about Split[...]
  • From: bsyehuda at gmail.com
  • Date: Wed, 22 Feb 2006 05:58:41 -0500 (EST)
  • References: <200602210331.WAA27805@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
boundedSplit[l_List, n_Integer] := Flatten[Partition[#, n, n, {1, 1}, {}] &
/@
   Split[l],1]
for example
x = {1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 2, 1,
     1, 1, 1, 1, 2, 1, 3, 3, 3, 2, 1};
and
boundedSplit[x,4]
returns
{{1, 1, 1, 1}, {1, 1, 1}, {2,
  2, 2, 2}, {2, 2, 2, 2}, {2, 2}, {3, 3, 3, 3}, {4}, {2}, {1, 1,
    1, 1}, {1}, {2}, {1}, {3, 3, 3}, {2}, {1}}
I hope this is what you want
regards
yehuda

On 2/21/06, Capet Arthur <Arthur.Capet at student.ulg.ac.be> wrote:
>
> the question...
>
> How can i restrict the maximum length of the sublist generated by the
> function Split[list, test] ?
>
>
> In details...
>
>   i need to subdivise a given list into sublists consisting into a given
> form (here it's p), repeated AT MAXIMUM k times, and then the
> just-following  element in the initial list :
>
> something like {p,... k times...,p, next})
>
> i've found -- Split [ll, #1 == p &] -- useful but don't know how to limit
> the length of the generated sublists (to k+1)
>
>
> thanks a lot
>
>
>
> Arthur Capet, ULG, Belgium
>
>


  • Prev by Date: JLink, Double.NaN, and arrays
  • Next by Date: General--Making the DisplayFormula style in ArticleModern look like Traditional
  • Previous by thread: question about Split[...]
  • Next by thread: Re: question about Split[...]