1-line idiom to replace if blocks

Justin Shaw wyojustin at hotmail.com
Tue Jan 21 21:27:04 EST 2003


> And, of course, if you really want short-circuiting, you can write this:
>
>     result=[lambda:value-if-false, lambda:value-if-true][condition]()
>
I like it except I'd add "[not not condition]" to ensure a 0 or a 1.
Justin Shaw






More information about the Python-list mailing list