lundi 20 janvier 2020

More than 2 rules for return in def() Python

If I create a function like this is any possible way to add more if, elif statements? continue for negative number or break for big values in one big line? Without if:if: tree? factorial() only for example.

from functools import reduce

def factorial(n):
    """return n!"""
    return 1 if n<2 else reduce(lambda x, y: x*y, {i+1 for i in range(n)}) 

Aucun commentaire:

Enregistrer un commentaire