Wednesday, January 17, 2018

Lambda and map in Python


Lambda:
Takes a number of parameters and an expression combining these parameters, and creates an anonymous function that returns the value of the expression:

Ex: :
adder = lambda x, y: x+y

print_assign = lambda name, value: name + '=' + str(value)

Map:
map() is a function which takes two arguments



r = map(func, seq)
The first argument func is the name of a function and the second a sequence (e.g. a list) seq. map() applies the function func to all the elements of the sequence seq


No comments:

Post a Comment