brainstate.util.flatten_dict

Contents

brainstate.util.flatten_dict#

brainstate.util.flatten_dict(d, parent_key='', sep='.')#

Flatten a nested dictionary.

Parameters:
  • d (Dict[str, Any]) – Dictionary to flatten.

  • parent_key (str) – Prefix for keys.

  • sep (str) – Separator between nested keys.

Returns:

Flattened dictionary.

Return type:

Dict[str, Any]

Examples

>>> d = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}}
>>> flatten_dict(d)
{'a': 1, 'b.c': 2, 'b.d.e': 3}