from typing import Any, List, Mapping


def _get_used_path(path: str | list[str]) -> str | list[str]:
    used_path = path
    if isinstance(used_path, str):
        used_path = [used_path]
    return used_path


def get_dict_value(dict_value: Mapping, path: str | List[str], default_value: Any = None) -> Any:
    result = default_value
    current_value = dict_value
    for field in _get_used_path(path):
        if current_value is not None and field in current_value:
            current_value = current_value[field]
            result = current_value
        else:
            result = default_value
            break

    if result is None:
        return default_value
    return result


def set_dict_value(dict_value: dict, path: str | List[str], value: Any):
    pivot = dict_value
    used_path = _get_used_path(path)
    last_index = len(used_path) - 1
    for i, p in enumerate(used_path):
        if i == last_index:
            pivot[p] = value
        else:
            if pivot.get(p) is None:
                pivot[p] = {}
            pivot = pivot[p]
