Flatten - Maple Help

ListTools

 Flatten
 flatten a list containing lists of elements

 Calling Sequence Flatten(L, N)

Parameters

 L - list N - non-negative integer

Description

 • The Flatten(L) function recursively converts any elements in a list which are of type list to expression sequences.
 • The Flatten(L, N) function flattens a nested list of lists $N$ times.
 Note: The inlined procedure $\mathrm{FlattenOnce}\left(L\right)$ is more efficient than a call to Flatten(L, 1).

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[1,2,3,\left[4,5,6\right]\right]$
 ${L}{≔}\left[{1}{,}{2}{,}{3}{,}\left[{4}{,}{5}{,}{6}\right]\right]$ (1)
 > $\mathrm{Flatten}\left(L\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (2)
 > $L≔\left[1,\left[2\right],\left[3,\left[4\right]\right],\left[\left[\left[5\right]\right],6\right]\right]$
 ${L}{≔}\left[{1}{,}\left[{2}\right]{,}\left[{3}{,}\left[{4}\right]\right]{,}\left[\left[\left[{5}\right]\right]{,}{6}\right]\right]$ (3)
 > $\mathrm{Flatten}\left(L\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (4)
 > $\mathrm{Flatten}\left(L,1\right)$
 $\left[{1}{,}{2}{,}{3}{,}\left[{4}\right]{,}\left[\left[{5}\right]\right]{,}{6}\right]$ (5)