from typing import MutableMapping
from typing import List


def flatten_dict(
    d: MutableMapping, parent_key: str = "", sep: str = "."
) -> MutableMapping:
    """Flattens nested dictionary structure.

    Args:
        d : dictionary to be flattened
        parent_key : optional parent key identifier
        sep : optional separator between parent and leaf keys
    Returns:
        Flattened dictionary
    """
    items: List = []
    for k, v in d.items():
        new_key = parent_key + sep + k if parent_key else k
        if isinstance(v, MutableMapping):
            items.extend(flatten_dict(v, new_key, sep=sep).items())
        else:
            items.append((new_key, v))
    return dict(items)