1-line idiom to replace if blocks

Justin Shaw wyojustin at hotmail.com
Wed Jan 22 03:27:04 CET 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