I want to use it once in a while, so I don't always remember it, so make a note.
prod.py
>>> import functools
>>> import operator
>>> prod = functools.partial(functools.reduce, operator.mul)
>>> print(prod([1, 2, 3]))
6
Excerpt from Docstring.
partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.
reduce(function, sequence[, initial]) -> value
mul(a, b) -- Same as a * b.
Documents for functools operator documentation
Simply use numpy
prod.py
>>> import numpy as np
>>> np.prod([1, 2, 3])
6
Recommended Posts