For review: PEP 308 - If-then-else expression
Andrew Dalke
adalke at mindspring.com
Mon Feb 10 04:53:08 EST 2003
David Eppstein:
> The question in these cases is not whether these people would find the
> correct construction -- obviously they wouldn't else they would use it
> in place of the ternary. The question is, without the ternary, what
> even worse construction would they use instead?
Ahh, good point.
For the two examples I gave, probably either
if x < y:
a = x
else:
a = y
(perhaps encapsulating that in a 'min' function ;)
And for 'hex_c = "0123456789ABCDEF"[i]'
if i < 10:
hex_c = chr(48 + i)
else:
hex_c = chr(55 + i)
or maybe
hex_c = chr(48 + i + (7 * (i>10)))
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list