LengthSplit - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

ListTools

 LengthSplit
 split a list into an expression sequence of sublists of a given length

 Calling Sequence LengthSplit( L, n ) LengthSplit( L, n, pad = expr )

Parameters

 L - list n - posint; the length of the sublists expr - (optional) anything; an expression to use for padding the last list to length n

Description

 • The LengthSplit command splits a list L into a sequence of sublists, each with n elements. If n does not divide evenly into $\mathrm{nops}\left(L\right)$, then the final sublist will have $\mathrm{irem}\left(\mathrm{nops}\left(L\right),n\right)$ elements, unless the $\mathrm{pad}=\mathrm{expr}$ option is given, in which case the value of expr will be used to fill out the final sublist to length $n$. If $n$ divides evenly into $\mathrm{nops}\left(L\right)$, then the pad option has no effect.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[\mathrm{seq}\right]\left(i,i=1..12\right)$
 ${L}{≔}\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}{,}{11}{,}{12}\right]$ (1)
 > $\mathrm{LengthSplit}\left(L,3\right)$
 $\left[{1}{,}{2}{,}{3}\right]{,}\left[{4}{,}{5}{,}{6}\right]{,}\left[{7}{,}{8}{,}{9}\right]{,}\left[{10}{,}{11}{,}{12}\right]$ (2)
 > $\mathrm{LengthSplit}\left(L,4\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}\right]{,}\left[{5}{,}{6}{,}{7}{,}{8}\right]{,}\left[{9}{,}{10}{,}{11}{,}{12}\right]$ (3)
 > $\mathrm{LengthSplit}\left(L,5\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}\right]{,}\left[{6}{,}{7}{,}{8}{,}{9}{,}{10}\right]{,}\left[{11}{,}{12}\right]$ (4)
 > $\mathrm{LengthSplit}\left(L,5,'\mathrm{pad}'=x\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}\right]{,}\left[{6}{,}{7}{,}{8}{,}{9}{,}{10}\right]{,}\left[{11}{,}{12}{,}{x}{,}{x}{,}{x}\right]$ (5)

 See Also