Real Pyhton - Appropiate Uses of Lambda Expressions
Example of a lambda function:
is_major_than_5 = lambda x: x > 5
assert is_major_than_5(6) == True
assert is_major_than_5(1) == FalseLambda with if statement:
is_between_1_and_10 = lambda x: True if (x > 1 and x < 10) else False
assert is_major_than_5(6) == True
assert is_major_than_5(-1) == FalseWhen NOT to use lambda functions:
Lambdas in Python tend to be the subject of controversies. Some of the arguments against lambdas in Python are:
- Issues with readability
- The imposition of a functional way of thinking
- Heavy syntax with the
lambdakeyword