import functools


def _render_key_path(key_path):
    """Given a key path, render it in a '[0]["all"][0]["keys"]'-like format."""
    def key_format(key):
        if isinstance(key, str):
            return "['{}']".format(key)
        else:
            return "[{}]".format(key)

    key_path_strs = [key_format(key) for key in key_path]
    key_path_trace = functools.reduce(lambda x, y: x + y, key_path_strs, "")
    return key_path_trace