<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#L149-L172) |

Flattens a possibly nested structure into a list.

    tf.keras.tree.flatten_with_path(
        structure
    )

This is a variant of flattens() which produces a
list of pairs: `(path, item)`. A path is a tuple of indices and/or keys
which uniquely identifies the position of the corresponding item.

Dictionaries with non-sortable keys are not supported.

#### Examples:

    keras.flatten_with_path([{"foo": 42}])
    [((0, 'foo'), 42)]

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A list of `(path, item)` pairs corresponding to the flattened version of the input `structure`. ||

<br />