I have a 1D list list={1,2,3,4,5,6,7,8,9} and I would like to partition it according to some specified sizes sizes={2,1,2,4}, where each element in sizes is the number of elements to include in each sublist. The desired result will be result={{1,2},{3},{4,5},{6,7,8,9}}. What would be a simple way to do this with list manipulations?
Asked
Active
Viewed 51 times
1
nanjun
- 1,297
- 6
- 15
Internal`PartitionRagged. – corey979 Apr 04 '19 at 20:48"System`"context asTakeList– b3m2a1 Apr 04 '19 at 20:51Internal`PartitionRaggedis usually faster thanTakeList... – Henrik Schumacher Apr 04 '19 at 20:56