lambda array python code example
Example 1: filter function using lambda in python
nums1 = [2,3,5,6,76,4,3,2]
bads = list(filter(lambda x: x>4, nums1))
print(bads)
Example 2: map function using lambda in python
nums1 = [2,3,5,6,76,4,3,2]
sq = list(map(lambda a : a*a, nums1))
print(sq)
Example 3: lambda function in python
Lamda is just one line anonymous function
Useful when writing function inside function
it can take multiple arguments but computes only one expression
Syntax:
x = lambda arguments : expression
Example 4: lambda function in python
>>> def identity(x):
... return x
These two functions do the same thing
>>> lambda x: x