Python Tutorial
lambda arguments: manipulation statement(arguments)
#!/usr/bin/python
mul = lambda a, b: a * b
print("mul(2,4): %d" % mul(2, 4))
Output:
$ python lambda_test.py mul(2,4): 8
map(function to apply, list)Example:
#!/usr/bin/python
list_arr = [10, 20, 30, 40, 50]
updated_list = map(lambda x: x*2, list_arr)
print(updated_list)
Output:
$ python lambda_test1.py [20, 40, 60, 80, 100]
filter(function_to filter, list)Example:
#!/usr/bin/python
list_arr = [10, 20, 30, 40, 50]
updated_list = filter(lambda x: x>20, list_arr)
print(updated_list)
Output:
$ python lambda_test2.py [30, 40, 50]
#!/usr/bin/python
from functools import reduce
list_arr = [10, 20, 30, 40, 50]
updated_list = reduce(lambda x,y: x+y, list_arr)
print(updated_list)
Output:
$ python lambda_test3.py 150
Python Tutorial
Privacy Policy | Copyright
2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page