So ,what is lambda function ? In every python code , we come across this devil .Let us crack this nut .
lambda is an anonymous function or throw away function, without a name .It is normally used when we do not want a function twice in the same program.
Basic Syntax :
lambda arguments : expression
Note :- lambda can contain 'n' number of arguments but it can have only one expression.
Examples :- c = lambda x :x +1
print(c(92))
The output will be 93.
Example :- a = [(1, 2), (4, 1), (9, 10), (13, -3),(-2,5)]
a.sort(key=lambda x: x[0])
print(a)
Output: [(13, -3), (4, 1), (1, 2), (9, 10)]
During the preprocessing of data , The lambda function is used in a wide range.Normally to map the delimiter in the csv files.
lambda is an anonymous function or throw away function, without a name .It is normally used when we do not want a function twice in the same program.
Basic Syntax :
lambda arguments : expression
Note :- lambda can contain 'n' number of arguments but it can have only one expression.
Examples :- c = lambda x :x +1
print(c(92))
The output will be 93.
Example :- a = [(1, 2), (4, 1), (9, 10), (13, -3),(-2,5)]
a.sort(key=lambda x: x[0])
print(a)
Output: [(13, -3), (4, 1), (1, 2), (9, 10)]
During the preprocessing of data , The lambda function is used in a wide range.Normally to map the delimiter in the csv files.
No comments:
Post a Comment