I have a list as follows:
listJP=Range[50]
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}
And I have another list indicating the positions where I want to create sublists
pos={5,12,24,38}
{5,12,24,38}
The values in the above list serve to show what position the list must quit and continue the next.
{list1,list2,list3,list4,list5}=listJP[[#]]&/@Rest@FoldList[Span[#[[-1]]+1,#2]&,{0},Append[Flatten[pos],Length[listJP]]]
{{1,2,3,4,5},{6,7,8,9,10,11,12},{13,14,15,16,17,18,19,20,21,22,23,24},{25,26,27,28,29,30,31,32,33,34,35,36,37,38},{39,40,41,42,43,44,45,46,47,48,49,50}}
This was a very good solution created by @Michael E2, but the Slot function still confuse me and so I would know if there is an in-built to do that.
I looked for something in Split, Partition, SpliBy, but unfortunately I did not succeed.
Internal`PartitionRagged[listJP, Prepend[Differences@Append[pos, Length@listJP], First@pos]]. – march Oct 20 '16 at 15:41