On Wed, 01 Feb 2006 14:34:26 -0600, "Michael Dudzik"
<[EMAIL PROTECTED]> said:
> On Wed, 1 Feb 2006 14:57:58 -0500, "Paul Winkler" <[EMAIL PROTECTED]>
> said:
> > Prior to python 2.5, there is AFAIK no other always-works
> > short-circuiting one-line conditional expression but this:
> > (bool(C) a
On Wed, 1 Feb 2006 14:57:58 -0500, "Paul Winkler" <[EMAIL PROTECTED]>
said:
> Prior to python 2.5, there is AFAIK no other always-works
> short-circuiting one-line conditional expression but this:
> (bool(C) and [foo] or [bar])[0]
Agreed that that works every time, but so does:
(bar,foo)[bool(C)]
On Wed, Feb 01, 2006 at 01:38:15PM -0600, Michael Dudzik wrote:
> But why not just use (bar,foo)[C] in all cases, regardless of the value
> of bar or foo?
Because it always evaluates both foo and bar, and sometimes you can't
afford that (e.g. if they are expensive expressions rather than
simple va
On Wed, 01 Feb 2006 20:26:24 +0100, "Florent Guillaume" <[EMAIL PROTECTED]>
said:
> Michael Dudzik wrote:
> > Sure, but what about when you don't know the boolean value ahead of
> > time, like:
> >
> >C and f(x) or g(x)
> >
> >On the other hand, (g(x), f(x))[C] works every time
> >
> > T
Michael Dudzik wrote:
Sure, but what about when you don't know the boolean value ahead of
time, like:
C and f(x) or g(x)
On the other hand, (g(x), f(x))[C] works every time
To be fair, both g(x) and f(x) are evaluated while
f(x) if C else g(x) # python 2.5, only evaluates the approp