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: [mg56913] Re: [mg56890] Partitioning a list from an index
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 10 May 2005 03:42:14 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Guy Israeli [mailto:guyi1 at netvision.net.il] 
To: mathgroup at smc.vnet.net
>Sent: Monday, May 09, 2005 7:46 AM
>Subject: [mg56913] [mg56890] Partitioning a list from an index
>
>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 
>
>
>

Partition will do, provided you calculate the appropriate kL:
 
In[66]:= spos = 6; n = 3;
In[67]:= k = n - Mod[spos - 1, n, 1] + 1
Out[67]= 2

In[68]:= Partition[list1, n, n, {k, 1}, {}]
Out[68]= {{1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 10}}

In[69]:= Position[%, e_ /; Length[e] < n, {1}, Heads -> False]
Out[69]= {{1}, {4}}

In[70]:= FlattenAt[%%, %]
Out[70]= {1, 2, {3, 4, 5}, {6, 7, 8}, 9, 10}


 
In[71]:= spos = 6; n = 2;
         k = n - Mod[spos - 1, n, 1] + 1;
         Partition[list1, n, n, {k, 1}, {}];
         Position[%, e_ /; Length[e] < n, {1}, Heads -> False];
         FlattenAt[%%, %]
Out[75]=
{1, {2, 3}, {4, 5}, {6, 7}, {8, 9}, 10}


--
Hartmut Wolf


  • Prev by Date: Re: ArcTan[1/0] no result, but ArcTan[Infinity] ok. How to resolve?
  • Next by Date: function definition difficulty
  • Previous by thread: Re: Partitioning a list from an index
  • Next by thread: Re: Partitioning a list from an index