1-line idiom to replace if blocks
Andrew Koenig
ark at research.att.com
Wed Jan 22 08:39:03 EST 2003
More information about the Python-list mailing list
Wed Jan 22 08:39:03 EST 2003
- Previous message (by thread): 1-line idiom to replace if blocks
- Next message (by thread): 1-line idiom to replace if blocks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> And, of course, if you really want short-circuiting, you can write this: >> result=[lambda:value-if-false, lambda:value-if-true][condition]() Justin> I like it except I'd add "[not not condition]" to ensure a 0 or a 1. You don't need to do that -- instead, you can write result=[lambda:value-if-true, lambda:value-if-false][not condition]() -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
- Previous message (by thread): 1-line idiom to replace if blocks
- Next message (by thread): 1-line idiom to replace if blocks
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list