Sep. 2, 2009
Python Ternary Operator
Here's a cool way to emulate the ternary operator in python:
{True: true-return, False: false-return}[expression]
For instance, suppose you wanted to output a string indicating a number of items:
print "Found %d item%s." % (numitems, \
{True: '', False: 's'}[numitems == 1])