[Python-3000] optimizing [x]range

Johan Dahlin jdahlin at async.com.br
Sun Jul 29 02:32:37 CEST 2007


Guido van Rossum wrote:
> Do we really need another way to spell a <= x < b?

FWIW, I'd say yes; I sometimes find it a bit difficult to remember
how the operator should be placed, there are several possible ways
of making a mistake, eg;

   a > x < b
   a < x > b
   a < x < b
   a > x > b

Now, the range syntax seems a bit strange at first, but I find it easier 
to parse:

   if x in range(a, b)

There's no way to incorrectly parse that, it's immediately known that 
the programmer tries to see whether x is in a specific range.

It seems to be used quite widely already;

http://google.com/codesearch?hl=en&q=+%5E.*if%5Cs%2B.*%5Cs%2Bin%5Cs%2Brange%5C(.*%24&start=10&sa=N

Johan


More information about the Python-3000 mailing list