Re: A NewBie Question
- To: mathgroup at smc.vnet.net
- Subject: [mg53612] Re: [mg53582] A NewBie Question
- From: Andrzej Kozlowski <akozlowski at gmail.com>
- Date: Thu, 20 Jan 2005 03:47:53 -0500 (EST)
- References: <200501190659.BAA06806@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 19 Jan 2005, at 07:59, 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 > Simplicity is, to some extend at least, in the eye of the beholder, but I suppose this is not as simple as what you had in mind: Reap[Fold[(Sow[Take[#1, #2]]; Drop[#1, #2]) & , ls, Range[2, 4]]][[2,1]] {{a, b}, {c, d, e}, {f, g, h, i}} Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/
- References:
- A NewBie Question
- From: Zhe Hu <iamhuzhe@gmail.com>
- A NewBie Question