Archive for the ‘lambda’ tag
if-else conditions in lambda functions
On reading my last post singular form of a word, a friend of mine (Sathya) didn’t understand what I had done in the lambda functions. It was of the form lambda w: w[-3:] == ‘ies’ and w[:-3] + ‘y’. I had forgotten to explain about that in that post.
There is one small restriction in lambdas - you can’t use if-else constructs in them. If you want to use a condition check in your lambda, then it has to be of this form
lambda : <condition> and <if block> or <else block>
This is easy to understand when you compare it with conditional or ternary operators in C (?:) - condition?if block:else block.

