Flattening a list: flatten

### 5.40.14 Flattening a list: flatten

The flatten command replaces any sublists of a list by their elements.

- flatten takes one argument:
  L, a list.
- flatten(L) returns a list which is the result of recursively replacing any elements that are lists by the elements, resulting in a list with no lists as elements.

#### Example

Input:

flatten([[1,[2,3],4],[5,6]])

Output:

⎡ ⎣ | 1,2,3,4,5,6 | ⎤ ⎦

If the original list is a matrix, you can also use the mat2list command for this (see Section 5.40.34).