Here lambda is used to create a one-line function for factorials.
A factorial one-line function (Python)
''' factorial_oneliner.py
get the factorial of integer n
tested with Python27 and Python34
'''
fact = lambda n: [1,0][n>1] or fact(n-1)*n
# test it ...
print(fact(53))
''' result ...
second line is mpmath result for comparison
4274883284060025564298013753389399649690343788366813724672000000000000
4274883284060025564298013753389399649690343788366813724672000000000000
'''
jamesjohnson25
0
Newbie Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
MIOCUNARD
0
Newbie Poster
mathwizurd
0
Newbie Poster
Tcll
66
Posting Whiz in Training
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.