Re: Partitioning a list from an index
- To: mathgroup at smc.vnet.net
- Subject: [mg56948] Re: Partitioning a list from an index
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Wed, 11 May 2005 05:24:03 -0400 (EDT)
- Organization: Uni Leipzig
- References: <d5mv78$e05$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, OverhangPartition[lst_, partlen_, over_] := Join[Take[lst, over], Partition[Drop[Drop[lst, over], -over], partlen], Take[lst, -over]] list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; In[]:=OverhangPartition[list1, 3, 2] Out[]={1, 2, {3, 4, 5}, {6, 7, 8}, 9, 10} In[]:=OverhangPartition[list1, 2, 1] Out[]={1, {2, 3}, {4, 5}, {6, 7}, {8, 9}, 10} Regards Jens "Guy Israeli" <guyi1 at netvision.net.il> schrieb im Newsbeitrag news:d5mv78$e05$1 at smc.vnet.net... > 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 > >