1 Resposta
+ 2
The main advantage (as I see it) is that lambda is a one-line function that can be used on the fly.
For example, in list comprehensions, maps, filters:
numbers = list(range(20))
[*filter(lambda x:x %2==0,numbers)] # take only pair numbers
or as a key in certain functions:
a = [2, 4, 9, 7]
indices = sorted(range(len(a)),key=lambda x:a[x]) # sort a
If you had to use a normal function using "def" if would be cumbersome and less effective.