iter_nest_dict¶
- iter_nest_dict(d: dict, iter_arrays: bool = False) Iterable[tuple][source][source]¶
Iterate over a nested dictionary, yielding the key and value.
- Parameters:
- Yields:
tuple– The key and value of the dictionary.- Return type:
Examples
>>> d = {'a': {'b': 1, 'c': 2}, 'd': {'e': 3, 'f': 4}} >>> for k, v in iter_nest_dict(d): ... print(k, v) ('a', 'b') 1 ('a', 'c') 2 ('d', 'e') 3 ('d', 'f') 4 >>> d = {'a': {'b': np.array([1, 2]), 'c': 2}, 'd': {'e': 3, 'f': 4}} >>> for k, v in iter_nest_dict(d, iter_arrays=False): ... print(k, v) ('a', 'b') [1 2] ('a', 'c') 2 ('d', 'e') 3 ('d', 'f') 4 >>> for k, v in iter_nest_dict(d, iter_arrays=True): ... print(k, v) ('a', 'b', 0) 1 ('a', 'b', 1) 2 ('a', 'c') 2 ('d', 'e') 3 ('d', 'f') 4