from functools import reduce


def get_nested(d, path):
    """
    Get value from a nested dictionary, addressing it via a list of keys
    indicating the value to the path.

    Example::

        >>> d = dict(a=dict(a0=0, a1=1))
        >>> get_nested(d, ['a', 'a1'])
        1

    If the path points to an undefined branch in the hierarchy, all required
    nested keys are added to the dictionary and an empty dictionary is added
    as value at that location.

    Example:

        >>> d = dict(a=dict(a0=0, a1=1))
        >>> get_nested(d, ['a', 'a2', 'new_dict'])
        >>> print(d)
        {'a': {'a0': 0, 'a1': 1, 'a2': {'new_dict': {}}}}


    :param d: nested dictionary to address;
    :param path: list of keys forming the path to the required entry;
    :return: entry from addressed path.
        """
    return reduce(lambda d, k: d.setdefault(k, {}), path, d)