y=if x>High: 2 elif x<Low: 1 else: 0
Hans Nowak
wurmy at earthlink.net
Wed May 22 17:59:57 EDT 2002
gr wrote:
>
> Hi,
> is there a simple possiblity to "teach" Python:
>
> y=if x>High: 2 elif x<Low: 1 else: 0
>
> instead of
>
> if x>High:
> y=2
> elif x<Low:
> y=1
> else:
> y=0
You mean, putting everything on one line? No. The best
you can get here is
if x > high: y = 2
elif x < low: y = 1
else: y = 0
It may be possible to put everything on one line using
some obfuscated functional idiom, but I won't go there. :-)
--
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
More information about the Python-list
mailing list