Combining colon statements on one line?
Phil Frost
indigo at bitglue.com
Fri Jul 16 07:37:04 EDT 2004
newdate = date + (1000,2000)[ date < 500 ]
On Thu, Jul 15, 2004 at 10:09:40PM -0700, Dave Blackington wrote:
>
> Hi, I'm trying to figure out how to combine an 'if'
> and 'else' statement on one line. Tonight I was
> programming and came up with a very short if/else
> scenario that demanded 4 lines due to the fact that
> python can't read an 'if' & 'else' on the same line.
> In order to do the same thing in 1 line, I needed to
> make a dictionary. If you want to know the whole
> scenario. Here it is:
>
> '972' '006'
>
> I have two dates without the millenium included.
> Using basic 'if' 'else' communication, this, it seems
> to me would require 4 lines of python to add the
> correct millenium. These lines will also be so short
> and waste a lot of blank space on the screen which
> could be devoted to other commands in your function.
> For digestion and organization purposes, it seems like
> it helps to limit your functions (whenever possible)
> to one screen. Taking up those 4 lines for such a
> simple short 'if' 'else' seems a bit much, no?
>
> I don't know if this is would be a desirable upgrade
> for other python users or not, but I figured I would
> mention it... assuming it's not already implemented.
>
> Thanks, -Dave
More information about the Python-list
mailing list