def _dict_from_key_path(segments, value):
    """Creates a nested dict out of array of keys."""
    ret = {}
    for segment in reversed(segments):
        if ret:
            ret = {segment: ret}
        else:
            ret[segment] = value
    return ret