Ad

Use reduce and be Happy!

Code
Diff
  • import functools
    def factorial(n: int) -> int:
        """Returns factorial of a non-negative integer."""
        return functools.reduce(lambda a,b: a*b, [i for i in range(2, n + 1)] or [1])
    • import functools
    • def factorial(n: int) -> int:
    • """Returns factorial of a non-negative integer."""
    • return eval("*".join(str(i) for i in range(2, n + 1)) or "1")
    • return functools.reduce(lambda a,b: a*b, [i for i in range(2, n + 1)] or [1])