def factor_conv(string, *, conv, factors):
    """Convert a string with a factor.

    The symbols from ``factors`` are compared to the end of ``string``
    until one matches. The ``string`` is then shortend by the the length
    of the symbol and the rest converted with ``conv`` and multiplied by
    the factor that corresponds to the symbol.

    >>> factors = {'h': 3600, 'm': 60, 's': 1}
    >>> factor_conv('10m', conv=int, factors=factors)
    600

    :param str string: input string
    :param conv: converter function
    :param dict factors: mapping from symbol to factor
    :return: converted value
    :raises ValueError: if the string cannot be converted
    """
    for sym in factors:
        if string.endswith(sym):
            if sym:
                return conv(string[:-len(sym)]) * factors[sym]
            else:
                return conv(string) * factors[sym]
    raise ValueError(f'invalid value: {string!r}')