# How to partition a 1D list according to specified lengths? [duplicate]

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?

• Look here, at InternalPartitionRagged. – corey979 Apr 4 '19 at 20:48
• @corey979 this is also now in the "System" context as TakeList – b3m2a1 Apr 4 '19 at 20:51
• But InternalPartitionRagged is usually faster than TakeList`... – Henrik Schumacher Apr 4 '19 at 20:56
• @b3m2a1 Thank you. This is really a neat function. According to the documentation, it is new in 11.2. – nanjun Apr 4 '19 at 20:58