Re: Partitioning a list from an index

*To*: mathgroup at smc.vnet.net*Subject*: [mg56933] Re: [mg56890] Partitioning a list from an index*From*: John Kiehl <john.kiehl at soundtrackny.com>*Date*: Tue, 10 May 2005 03:42:49 -0400 (EDT)*Reply-to*: John Kiehl <john.kiehl at soundtrackny.com>*Sender*: owner-wri-mathgroup at wolfram.com

Guy, what a fun question! You don't make it really clear how you make "6" the priviledged index, so that got me thinking of a solution that takes advantage of Mathematica's "dialog" quality where I might be deciding as I go along which index is the one I want to syncronize to. My solution is somewhat unlikely, as I start by "over partitioning" your list, so that EVERY index appears as the first element in some sublist. And then, at that point, extract every other (or every third) sublist starting from the chosen sublist. BUt again, as I said above this is all in keeping with my interpretation of how I might be playing with this list of numbers. Let width=the size of your desired partitions. In[1] width=3; list1=Range[10]; In[2] p=Partition[list1,width,1] (* "over partition" the list *) Out[2]={{1,2,3},{2,3,4},{3,4,5},{4,5,6},{5,6,7},{6,7,8},{7,8,9},{8,9,10}} In[5]:= pp=Partition[p,width] (* Partition a second time *) Out[5]= {{{1,2,3},{2,3,4},{3,4,5}},{{4,5,6},{5,6,7},{6,7,8}}} (* we can see that 6 appears as the first element in the thrid sublist *) (* so this Part[] command will extract all the appropriate sublists *) (* in my second example below we'll let Position[pp,6] make this observation for us *) In[7]:=pp[[All,3]] Out[7]={{3,4,5},{6,7,8}} (* bigger example -- still looking to align on "6" *) In[9]:= width =4; list1=Range[42]; In[11]:= p=Partition[list1,width,1]; In[12]:= pp=Partition[p,width]; In[13]:= (* we're looking for a 1 as the final element in the values below *) In[14]:= Position[pp,6] Out[14]= {{1,3,4},{1,4,3},{2,1,2},{2,2,1}} In[15]:= (* and now we know we want the second sublist from each *) pp[[All,2]] Out[15]= {{2,3,4,5},{6,7,8,9},{10,11,12,13},{14,15,16,17},{18,19,20,21}, {22,23,24,25},{26,27,28,29},{30,31,32,33},{34,35,36,37}} Cheers, john kiehl On Monday, May 9, 2005 1:46 AM, Guy Israeli <guyi1 at netvision.net.il> 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 > > >