Re: Looking for ?: operator...

Jim Roskind (jar@infoseek.com)
Fri, 16 Sep 1994 10:40:32 -0700

> From: Guido.van.Rossum@cwi.nl
> Date: Fri, 16 Sep 1994 12:31:14 +0200
>
> > Is there something I can use similar to C's ?: operator??
>
> Steve Majewski (or was it Tim Peters?) suggested the following
> solution: (a and [b] or [c])[0].

For the record, if you're gonna' have such an ugly construct as part
of your standard working set ;-), you might as well use tuples instead
of lists. It does cost an extra pair of (uglifying) commas, but it
runs marginally faster. In general, singleton tuple creation (on my
platform) is roughly twice as fast as singleton list creation
(probably because of the number of allocations required). In general,
it is a stupid (i.e., small) amount of speed up (and would only be
*critical* in a very hot loop) but it seems reasonable to consistently
use efficient constructs when you have the chance. :-) (...and it is
soooo ugly to start with, it is hard to assert it got worse ;-) ).

The equivalent solution using tuples is then:

(a and (b,) or (c,))[0]

Jim

-- 
Jim Roskind
voice: 408.982.4469
fax: 408.986.1889
jar@infoseek.com