Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Partitioning a list from an index

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56953] Re: Partitioning a list from an index
  • From: bghiggins at ucdavis.edu
  • Date: Wed, 11 May 2005 05:24:08 -0400 (EDT)
  • References: <d5mv78$e05$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Guy, Here is one way to do the task:

partitionfunc[start_, size_, alist_] := alist /. {x1___,
    x_ /; x == start, y___} :> {x1, Apply[
    Sequence, Partition[Flatten[{x, Drop[{y}, -Mod[Length[{x, y}],
size]]}],
      size]], Apply[Sequence, Take[{y}, -Mod[Length[{x, y}], size]]]}

In[57]:=partitionfunc[4,2,list1]

Out[57]={1,2,3,{4,5},{6,7},{8,9},10}

I am sure others will have a less kludgy way to do it.

Cheers,

Brian


Guy Israeli wrote:
> hello,
>
> how can partition a list (doesn't have to be with 'Partition') such
that the
> partition will begin with a specific index?
>
> like this:
>
> list1={1,2,3,4,5,6,7,8,9,10}
>
> and i might want to split it to pairs or threes from index 6 for
example, so
> for threes it will be
>
> {1,2,{3,4,5},{6,7,8},9,10}
>
> with or without padding to those that are left, depends on what it is

> possible, or maybe put them together or something
>
> for pairs it will be {1,{2,3},{4,5},{6,7},{8,9},10}
> again with or without padding
> 
> thank you very much
> 
> Guy


  • Prev by Date: Re: solve() problem since new ROM update
  • Next by Date: Re: Re: FilledPlot: Curves->Back option and Epilog not working?
  • Previous by thread: Re: Partitioning a list from an index
  • Next by thread: Re: Partitioning a list from an index