from typing import Union
from typing import Any
from typing import Dict
from typing import List


def lookup_path(path: str, dict_: Union[Any, Dict[str, Any]]) -> Any:
    """
    Recursively traverse a potentially nested dictionary
    using the '.' separated path.

    >>> lookup_path("k0.k1.k2", {"k0": {"k1": {"k2": 42}}})
    42
    """

    def _lookup(p: List[str], data: Union[Any, Dict[str, Any]]) -> Any:
        if not p:
            return data
        else:
            try:
                return _lookup(p[1:], data[p[0]])
            except KeyError:
                raise LookupError(p[0])

    return _lookup(path.split("."), dict_)