conditionals in lambdas?

Steve Horne sh at ttsoftware.co.uk
Thu Nov 9 07:48:46 EST 2000


On 3 Nov 2000 19:39:07 GMT, msoulier at nortelnetworks.com (Michael P.
Soulier) wrote:

>    Hey people. If I want to put conditions in a lambda function, how would I
>go about that? 
>
>def test(string):
>    if string[:3] == 'yes:
>        return 1
>    else:
>        return 0

The case you are trying to do is handled by other answers, but there
is a simple trick to doing this for conditions in general...

  ([no_result, yes_result] [(condition) + 1])

ie - put the possible answers in a list and then use the condition to
derive the subscript.

-- 
Steve Horne
sh at ttsoftware.co.uk



More information about the Python-list mailing list