Skip to content

Dict

Dictionary utility functions.

Authors

Kadek Denaya (kadek.d.r.diana@gdplabs.id)

References

NONE

flatten_dict(nested_dict, parent_key='', sep='.')

Flatten a nested dictionary into a single level dictionary.

Parameters:

Name Type Description Default
nested_dict dict[str, Any]

The nested dictionary to flatten.

required
parent_key str

The parent key to prepend to the keys in the flattened dictionary. Defaults to empty string.

''
sep str

The separator to use between the parent key and the child key. Defaults to ".".

'.'

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The flattened dictionary.

Examples:

nested = {"a": {"b": 1, "c": 2}, "d": 3}
flattened = flatten_dict(nested)
# Result: {"a.b": 1, "a.c": 2, "d": 3}