For review: PEP 308 - If-then-else expression

David Eppstein eppstein at
Mon Feb 10 07:39:54 CET 2003

In article <b27eq5$7ld$1 at>,
 "Andrew Dalke" <adalke at> wrote:

> Now my other analysis suggests a misuse rate roughly equal to
> a use rate.  Eg, people will use
>   a = x if x < y else y
> instead of
>   a = min(x, y)
> and people will do
>   s = chr(48 + i if i < 10 else 55 + i)
> instead of
>   s = "0123456789ABCDEF"[i]

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?

BTW, I think your estimate of a correct use per 1000 lines sounds about 
right.  Which is one reason I don't feel very strongly about this 

David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at

More information about the Python-list mailing list