In [24]:
import sys
import numpy as np

In [ ]:
#when running this program, recommend using parallel
#cat input.list | parallel python3 factrical.py {}

In [ ]:
def main():
    #get the first parameter
    input_n=int(sys.argv[1].strip())
    if type(input_n) is int:
        if input_n == 0:
            print("%d's factorial is 1"%input_n)
        else:
            candidates=[i for i in range(1,input_n+1)]
            result=np.prod(np.array(candidates))
            print("%d's factorial is %d"%(input_n,result))

In [ ]:
if __name__ == '__main__':
    main()

In [4]:
from functools import reduce
a=[1,2,3,4,5,6]
reduce(lambda x,y:x*y,a)


Out[4]:
720

In [5]:
help(reduce)


Help on built-in function reduce in module _functools:

reduce(...)
    reduce(function, sequence[, initial]) -> value
    
    Apply a function of two arguments cumulatively to the items of a sequence,
    from left to right, so as to reduce the sequence to a single value.
    For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
    ((((1+2)+3)+4)+5).  If initial is present, it is placed before the items
    of the sequence in the calculation, and serves as a default when the
    sequence is empty.