Trinary operator?

Alex Martelli aleax at aleax.it
Wed Apr 17 16:59:27 EDT 2002


Philipp Lenssen wrote:
        ...
> likey, '... name="' + (key == 'station') ? 'lastStation' : key + '" ...'

name = '"' + (key, 'lastStation')[key == 'station'] + '" ...'

or even better:

name = '"%s" ...' % (key, 'lastStation')[key == 'station']


Alex




More information about the Python-list mailing list