def horner (x, ai) :
    """Value of polynomial `a0 + a1 * x + a2 * x**2 + ... an * x ** n` for `x`.

       >>> horner (3, (-1, 2, -6, 2))
       5
       >>> horner (-3, [8, -1, 0, 13, 4])
       -16
    """
    ia     = reversed (ai)
    result = next     (ia)
    for a in ia :
        result *= x
        result += a
    return result