<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.utils.iterate_nested" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.utils.iterate_nested

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/utils/tf_functions.py">View source</a>



Creates an iterator over every leaf value in depth first order.

```python
tf_quant_finance.utils.iterate_nested(
    nd, previous_keys=None
)
```



<!-- Placeholder for "Used in" -->

Iterates over a nested dictionary in depth first order. The order in which
the peer keys are traversed is not guaranteed (same as for the keys of a
dictionary).

```Example
nested_dict = {'a': 1, 'b': [2, 3, 4], 'c': {'d': 8}}
for k, v in iterate_nested(nested_dict):
  print('_'.join(k), v)
# Prints out:
# a: 1
# b: [2, 3, 4]
# c_d: 8
```

#### Args:


* <b>`nd`</b>: The dictionary to be traversed.
* <b>`previous_keys`</b>: If supplied, the computed key list will be a join of the
  previous_keys and the current keys.


#### Yields:

A tuple of the key path and the value for each leaf node.
