### 6.3.13 Flattening a list

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

- flatten takes 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

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

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

##### Remark.

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