y=if x>High: 2 elif x<Low: 1 else: 0
Andrew Dalke
dalke at dalkescientific.com
Wed May 22 18:19:55 EDT 2002
Hans Nowak wrote:
>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. :-)
No problem, I will
y = (x>high)*2 + (x<low)
This assumes low <= high.
But please don't use this in real code.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list