[Python-3000] optimizing [x]range

Georg Brandl g.brandl at gmx.net
Sun Jul 29 07:41:58 CEST 2007


Johan Dahlin schrieb:
> 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.

What about floats?

Currently, "3.5 in range(5)" is False, while "0 <= 3.5 < 5" is True.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-3000 mailing list