TakeList

TakeList[list,{n1,n2,}]

gives the list of results obtained by successively taking ni elements from list.

TakeList[list,{seq1,seq2,}]

successively uses the sequence specifications seqi.

TakeList[list,seqs1,seqs2,]

gives a nested list in which elements specified by the lists seqsi are taken at level i in list.

Details

Examples

open allclose all

Basic Examples  (5)

Take sublists of different lengths from a list of symbols:

Take sublists from the end:

Take two elements, then three elements, and then all the rest:

Take two elements, then three elements, and then up to 10 and five if present:

Take a list of subexpressions from an expression with any head:

Scope  (2)

Take sublists using different sequence specifications:

Take subblocks of different sizes from a matrix:

Properties & Relations  (5)

TakeList[list,seqs] is equivalent to FoldPairList[TakeDrop,list,seqs]:

TakeList[list,{n,,n}] is equivalent to Partition[list,n] for an appropriate number of take specifications:

The equivalent of Partition[list,UpTo[n]] may require an additional take specification:

Subdivide a list in sublists of different lengths using TakeList:

The original list can be reconstructed using Flatten:

Subdivide an array in blocks of different sizes using TakeList:

The original matrix can be reconstructed with ArrayFlatten:

Take a list of expressions with the same head and any lengths:

Join those expressions into a single expression with the common head:

The original list can be reconstructed with TakeList by giving the lengths of the subexpressions:

Introduced in 2017
 (11.2)