Python lambda function to calculate factorial of a number

前端 未结 11 1334
误落风尘
误落风尘 2020-12-30 12:00

I have just started learning python. I came across lambda functions. On one of the problems, the author asked to write a one liner lambda function for factorial of a number.

11条回答
  •  长情又很酷
    2020-12-30 12:54

    Very nicely explained! Only one minor fix: if b > 1 NOT if b > 0

    The result is the same but logically more correct as it is executing one unnecessary additional loop (even though multiplying by 1)

    Wikipedia => n!, is the product of all positive integers less than or equal to n

提交回复
热议问题