In [1]:
N = 10**6
MOD = 10**9+7
In [2]:
%%timeit
fact = [1]
for n in range(1,N):
    fact.append(fact[-1]*n%MOD)
200 ms ± 671 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)