PYTHON ASSIGNMENT
Spacific cases or condition in which a Python programmer should prefer lambda expressions over (standard) functions
when there is need of a tiny piece of logic, lambda saves from writing a whole fuction.e.g check_even = lambda x:
x%2 = = 0
When there is need to sort or filter someting based on a simple rule.e.g
nanes = ["sarah" , "ali" , "badar"]
sorted = sorted (names , key = lambda x: len(x))
When working with tools like map, filter, reduce : these functions expect another function as input. Lambda lets us
plug in the logic right there.
number = [1,2,4,5,]
squares = list ( map (lambda x:x**2, number))
To get a quick response function without clutter.
button.on_click ( lambda e: print ("clicked!"))
When to use normal functions instead
If the logic is long or complex (loops , multiple steps).
If there is need to reuse the function in different places.
If we want to document the function with a name and explanation.