[Python-3000] optimizing [x]range

Guido van Rossum guido at python.org
Sun Jul 29 19:33:34 CEST 2007


On 7/28/07, Johan Dahlin <jdahlin at async.com.br> wrote:
> 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

Were you drunk at the time? :-)

> 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

Sorry, 50 hits is not "quite widely".

Did you find *any* examples using a step > 1?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list