import builtins


def from_str_to(type_):
    """Return a cast function to convert a string to a builtin type.

    The `type` parameter is the name of the type as a string. Returns the
    builtin Python cast function if `type` is "str", "int", or "float". If
    `type` is "bool", the returned cast function will return `True` for the
    values "y", "yes", "true", and "1" (case insensitive), otherwise it will
    return `False`. For any other `type` specified, the builtin `str`
    function is returned.

        >>> f = from_str_to("str")
        >>> f("hello")
        "hello"

        >>> f = from_str_to("int")
        >>> f("10")
        10

        >>> f = from_str_to("float")
        >>> f("10")
        10.0

        >>> f = from_str_to("bool")
        >>> [f(s) for s in ['yes', 'no', 'true', 'false']]
        [True, False, True, False]
    """
    if type_ in ("str", "int", "float"):
        return getattr(builtins, type_)
    if type_ == "bool":
        return lambda s: s.lower() in ("y", "yes", "true", "True", "1")
    return str