y=if x>High: 2 elif x<Low: 1 else: 0

Hans Nowak wurmy at earthlink.net
Wed May 22 18:30:43 EDT 2002


Andrew Dalke wrote:

> Hans Nowak wrote:
> >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.

Ah, well, this seems kinda alright... I was thinking along the
lines of the infamous

  (a and [b] or [c])[0]

idiom... I don't know if a variant of this is possible in this 
case, and probably don't want to know. :-)

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) 
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/



More information about the Python-list mailing list