Ed Leafe wrote:
> On Nov 18, 2008, at 4:43 PM, Paul McNett wrote:
>
>   
>> But yes, I love iif(), and wish Python had it.
>>     
>
>
> def iif(comp, trueVal, falseVal):
>       return {True: trueVal, False: falseVal}[bool(comp)]
>
>       I think that was one of the first Python scripts I ever wrote!
>   

Python DOES have it built in (at least as of 2.5), check 2.5 docs under
"What's New" - Pep 308 :

>>> x = true_value if condition else false_value


And if you wish a one liner do case then you can do :

x = {'one possibility': 1
    , 'another one':2
    , 'the next one is numeric':3
    , 125: 4}.get(test_expression, 'Not found')

(yup smarties, it is a one liner even if I choose to span it through
multiple lines ;c)  )







_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to