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.

Tags: ,

2 comments

  1. >> llambda : <condition > and <if block> or < else block >

    you mean lambda : __condition__ and __true statement__ or __false statement__ Correct ??

  2. Yeah. I meant that only.

Leave a comment