from functools import reduce
import operator


def product(seq, fn=None):
    """Multiply the elements seq[i], or fn(seq[i]) if fn is given.
    product([1, 2, 3]) ==> 6; product([1, 2, 3], lambda x: x*x) ==> 1*4*9"""
    if fn:
        seq = map(fn, seq)
    return reduce(operator.mul, seq, 1)