Re: A NewBie Question
- To: mathgroup at smc.vnet.net
- Subject: [mg53614] Re: [mg53582] A NewBie Question
- From: János <janos.lobb at yale.edu>
- Date: Thu, 20 Jan 2005 03:47:57 -0500 (EST)
- References: <200501190659.BAA06806@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Newbie answer:
In[47]:=
data = {a, b, c, d, e, f, g,
h, i, j, k, l}
ind = {2, 3, 4}
Out[47]=
{a, b, c, d, e, f, g, h, i,
j, k, l}
Out[48]=
{2, 3, 4}
In[85]:=
Table[{Take[data,
{Sum[ind[[x]], {x, 1,
y}] - ind[[y]] + 1,
Sum[ind[[x]], {x, 1,
y}]}], Complement[
Take[data,
{Sum[ind[[x]], {x, 1,
y}] - ind[[y]] + 1,
Length[data]}],
Take[data,
{Sum[ind[[x]], {x, 1,
y}] - ind[[y]] + 1,
Sum[ind[[x]], {x, 1,
y}]}]]}, {y, 1, 3}][[
All,1]]
Out[85]=
{{a, b}, {c, d, e},
{f, g, h, i}}
János
P.S. I am sure there is a better way with Fold, I just do not feel Fold
enough.
On Jan 19, 2005, at 1:59 AM, Zhe Hu wrote:
> Is there a way to take parts of a list as follows:
>
> takeParts[{a,b,c,d,e,f,g,h,i}, {2,3,4}]
>
> {{a,b}, {c,d,e}, {f,g,h,i}}
>
> A tedious way might be transforming {2, 3, 4} into {{1,2}, {3,5}, {6,
> 9}} (by Fold) and then Part/@ onto it. Is there a simpler way to do
> it?
>
> Thanks,
> Hu Zhe
>
- References:
- A NewBie Question
- From: Zhe Hu <iamhuzhe@gmail.com>
- A NewBie Question