from typing import Union
from typing import Any


def get(d: dict, keys: Union[str, list[str]], safe: bool = True) -> Any:
    """Get dict value by keys.

    Args:
        d (dict): Target dict.
        keys (List[str]): Keys.
        safe (bool, optional): Safe or not.

    Raises:
        KeyError: Not found key on safe=False.

    Returns:
        Any: Value.
    """
    if isinstance(keys, str):
        keys = [keys]
    result = d.copy()
    for k in keys:
        try:
            result = result[k]
        except TypeError as err:
            if safe:
                return None
            else:
                raise err
        except KeyError as err:
            if safe:
                return None
            else:
                raise err
    return result