def totype(v, default):
    """
    Tries to convert the value 'v' into the same type as 'default'.

        >>> totype('24', 0)
        24
        >>> totype('True', False)
        True
        >>> totype('0', False)
        False
        >>> totype('1', [])
        '1'
        >>> totype('none', True)  #doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        TypeError
    """
    if isinstance(default, bool):
        lv = v.lower()
        if lv in ("true", "yes", "on", "1"):
            return True
        elif lv in ("false", "no", "off", "0"):
            return False
        raise TypeError
    elif isinstance(default, int):
        return int(v)
    elif isinstance(default, float):
        return float(v)
    return v