from math import exp


def expweight(lst, fromt=None, fac=1.0):
    """Weights values in list of ``(value, time)`` pairs exponentially by time and returns the sum.
    If `fromt` is not `None`, then subtracts it from each time first.
    Each time is multiplied by the given factor, prior to exponentiation (default 1.0).
    """
    ret = 0.0
    tot = 0.0
    for v, t in lst:
        if fromt is not None:
            t -= fromt
        t *= fac
        ret += exp(t)*v
        tot += exp(t)
    ret /= tot
    return ret