Use functools.reduce.