def flatten(d):
    """
    This flattens a nested dictionary.

    Args:
        d (dict|list): The object to flatten.

    Returns:
        flat_d (dict): The flattened object.
    """
    def recurse(value, parent_key=""):
        if isinstance(value, list):
            for i in range(len(value)):
                recurse(value[i], f'{parent_key}.{str(i)}' if parent_key else str(i))
        elif isinstance(value, dict):
            for k, v in value.items():
                recurse(v, f'{parent_key}.{k}' if parent_key else k)
        else:
            obj[parent_key] = value

    obj = {}
    recurse(d)
    return obj