MathGroup Archive 2005

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

Search the Archive

Re: Partitioning a list from an index

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

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;

In[2]  p=Partition[list1,width,1]   (* "over partition" the list *)

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

(* bigger example -- still looking to align on "6" *)

In[9]:=   width =4;
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 *)
Out[15]=  {{2,3,4,5},{6,7,8,9},{10,11,12,13},{14,15,16,17},{18,19,20,21},

john kiehl

On Monday, May 9, 2005 1:46 AM, Guy Israeli <guyi1 at> wrote:
>how can partition a list (doesn't have to be with 'Partition') such that the 
>partition will begin with a specific index?
>like this:
>and i might want to split it to pairs or threes from index 6 for example, so 
>for threes it will be
>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

  • Prev by Date: Math5.0 frustrated Compatibility Problem
  • Next by Date: Re: Folding Deltas
  • Previous by thread: Re: Partitioning a list from an index
  • Next by thread: Re: Partitioning a list from an index