from functools import reduce
from operator import getitem


def _get_by_path(tree, keys):
    """
    访问tree（config：json）结构的，所有keys项
    （为了设置新配置，要访问旧配置时使用）
    Access a nested object in tree by sequence of keys.

    :param tree: （config：json）
    :param keys: keys项
    :return: （json的k:v）
    """

    """
    getitem()，根据keys从tree（config：json）中获取k:v

    reduce(function, sequence[, initial]) -> value
    Apply a function of two arguments cumulatively to the items of a sequence,
    from left to right, so as to reduce the sequence to a single value.
    For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
    ((((1+2)+3)+4)+5). 
    If initial is present, it is placed before the items of the sequence in the calculation,
    and serves as a default when the sequence is empty.
    """
    return reduce(getitem, keys, tree)