<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/tree/tree_api.py#L108-L146) |

Flattens a possibly nested structure into a list.

    tf.keras.tree.flatten(
        structure
    )

In the case of dict instances, the sequence consists of the values,
sorted by key to ensure deterministic behavior. However, instances of
`collections.OrderedDict` are handled differently: their sequence order is
used instead of the sorted keys. The same convention is followed in
`pack_sequence_as`. This correctly unflattens dicts and `OrderedDict` after
they have been flattened, or vice-versa.

Dictionaries with non-sortable keys are not supported.

#### Examples:

    keras.tree.flatten([[1, 2, 3], [4, [5], [[6]]]])
    [1, 2, 3, 4, 5, 6]
    keras.tree.flatten(None)
    [None]
    keras.tree.flatten(1)
    [1]
    keras.tree.flatten({100: 'world!', 6: 'Hello'})
    ['Hello', 'world!']

<br />

<br />

<br />

| ## Args ||
|---|---|
| `structure` | An arbitrarily nested structure. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A list, the flattened version of the input `structure`. ||

<br />