flatten

bandicoot.utils.flatten(d, parent_key='', separator='__')

Flatten a nested dictionary.

Parameters

d: dict_like

Dictionary to flatten.

parent_key: string, optional

Concatenated names of the parent keys.

separator: string, optional

Separator between the names of the each key. The default separator is '_'.

Examples

>>> d = {'alpha': 1, 'beta': {'a': 10, 'b': 42}}
>>> flatten(d) == {'alpha': 1, 'beta_a': 10, 'beta_b': 42}
True
>>> flatten(d, separator='.') == {'alpha': 1, 'beta.a': 10, 'beta.b': 42}
True