Some syntactic sugar proposals

Brian Blais bblais at bryant.edu
Mon Nov 15 13:49:34 EST 2010


On Nov 15, 2010, at 1:39 AM, Dmitry Groshev wrote:

>    if x in range(a, b): #wrong!
> it feels so natural to check it that way, but we have to write
>    if a <= x <= b
> I understand that it's not a big deal, but it would be awesome to have
> some optimisations - it's clearly possible to detect things like that
> "wrong" one and fix it in a bytecode.

I don't think anyone has pointed this out, but these are *not* the same thing.  observe:


x=3
if x in range(1,10):
    print "yay!"
    
if 1<=x<10:
    print "yay too!"
    
x=3.2
if x in range(1,10):
    print "yay!"
    
if 1<=x<10:
    print "yay too!"
    
output:

yay!
yay too!
yay too!


						bb
-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/






More information about the Python-list mailing list