0

I read that lambda can have any number of arguments and it must have only one expression

Take a look at the below code

from functools import reduce
a = [1,2,3,4,5]
result = reduce(lambda x,y: x if x > y else y, a)
print(result)

Output

5

In the above expression, lambda is having if and else both. Is it considered as only one expression ?

Nitesh
  • 1,715
  • 3
  • 27
  • 47

0 Answers0