RosettaCodeData/Task/Factorial/Python/factorial-5.py

14 lines
240 B
Python
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
from itertools import (accumulate, chain)
from operator import mul
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
# factorials :: [Integer]
def factorials(n):
return list(
accumulate(chain([1], range(1, 1 + n)), mul)
)
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
print(factorials(5))
2016-12-05 22:15:40 +01:00
2019-09-12 10:33:56 -07:00
# -> [1, 1, 2, 6, 24, 120]