from typing import Any


def ret(d: dict, key: str) -> Any:
    """ Unwrap nested dictionaries in a recursive way.

    Parameters
    ----------
    d: dict
        Python dictionary
    key: str or Any
        Key or chain of keys. See example below to
        access nested levels.

    Returns
    ----------
    out: Any
        Value from the key or value from the
        last key from the chains.


    Examples
    ----------
    >>> a = {"toto": {"titi":1}, "tutu":2}
    >>> ret(a, "tutu")
    2

    >>> ret(a, "toto")
    {"titi":1}

    >>> ret(a, "toto:titi")
    1
    """
    if ":" in key:
        # Split at first ":"
        level = key.split(":", maxsplit=1)
        if isinstance(d[level[0]], dict):
            return ret(d[level[0]], level[1])
        else:
            raise AssertionError("""
            Nested level must be dictionaries!
            d[{}] is not a dict!
            """.format(level[0]))
    return d[key]