alfred3.util.flatten_dict#

alfred3.util.flatten_dict(d: dict, prefix_sep: str = '_', sequences_to_dict: bool = True) dict[source]#

dict: Turns a nested dictionary into a flat one.

Keys of subdictionaries are concatenated, e.g. {"k1": {"s1": "value"}} would result in {"k1_s1": "value"}. The sperator can be defined in the argument prefix_sep.

If sequences_to_dict is true, values that are iterable sequences like lists, tuples or generators (but not strings), will be turned into dictionaries and identified with unique keys aswell. In this case, the resulting output will be a dictionary where each entry is a pair of a single key with a single value.