Re: Most compact "X if X else Y" idiom

2008-10-11 Thread jbperez808
Thanks, folks. Short-circuit boolean was the syntax I had in mind which momentarily escaped me, but the "if not x: x='blah'" idiom was instructive as well. -- http://mail.python.org/mailman/listinfo/python-list

Re: Most compact "X if X else Y" idiom

2008-10-11 Thread Steven D'Aprano
On Sun, 12 Oct 2008 05:30:33 +, Steven D'Aprano wrote: > Use short-circuit Booleans: > > y = x or "blah" Except of course you don't use x, you use the complex expression. y = (some complex expression) or "blah" Sorry for the itchy posting finger. -- Steven -- http://mail.python.org/m

Re: Most compact "X if X else Y" idiom

2008-10-11 Thread Steven D'Aprano
On Sat, 11 Oct 2008 22:01:46 -0700, jbperez808 wrote: > I find myself having to do the following: > > x = (some complex expression) > y = x if x else "blah" > > and I was wondering if there is any built-in idiom that can remove the > need to put (some complex expression) in the temporary var

Re: Most compact "X if X else Y" idiom

2008-10-11 Thread Aaron "Castironpi" Brady
On Oct 12, 12:01 am, [EMAIL PROTECTED] wrote: > I find myself having to do the following: > >   x = (some complex expression) >   y = x if x else "blah" > > and I was wondering if there is any built-in idiom that > can remove the need to put (some complex expression) > in the temporary variable x.

Re: Most compact "X if X else Y" idiom

2008-10-11 Thread Terry Reedy
[EMAIL PROTECTED] wrote: I find myself having to do the following: x = (some complex expression) y = x if x else "blah" and I was wondering if there is any built-in idiom that can remove the need to put (some complex expression) in the temporary variable x. A common idiom for this particu

Most compact "X if X else Y" idiom

2008-10-11 Thread jbperez808
I find myself having to do the following: x = (some complex expression) y = x if x else "blah" and I was wondering if there is any built-in idiom that can remove the need to put (some complex expression) in the temporary variable x. e.g. something like the below: y= foobar ((some complex e