def _list_formatter(lst, fun=None):
    """
    Returns a function that takes x, pos and returns fun(lst[x]) if fun is not
    None, else lst[x] or "" if x is out of range.
    """

    def _fun(x, pos):
        x = int(x)
        if x >= len(lst) or x < 0:
            return ""

        elem = lst[x]
        if fun is None:
            return elem
        return fun(elem)

    return _fun