def sum ( a, b ): # non anonymous
return a+b
print (sum(1, 2)) # 3
sum = lambda a,b: (a+b) # anonymous / lambda
print (sum(1, 2)) # 3
# You have to save the lambda expresion for it to work
nameOfLambda = lambda arg1, arg2: expression
#define a function inline
#(syntax) lambda parameter_list: expression parameter_list is comma separated
#lambda implicitly returns its expression's value, thus equivalent to any simple fxn of form...
'''
def function_name(parameter_list)
return expression
'''
numbers = [10, 3, 7, 1, 9, 4, 2, 8, 5, 6]
print(list(filter(lambda x: x%2 != 0, numbers))) #here filter() takes a fxn as 1st argument
# [3, 7, 1, 9, 5]
class MicroMock(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def print_foo(x):
print x.foo
print_foo(MicroMock(foo=3))