range() is not the best way to check range?

Leif K-Brooks eurleif at ecritters.biz
Tue Jul 18 07:09:16 EDT 2006


Grant Edwards wrote:
> Using xrange as somebody else suggested is also insane.

Sorry about that, I somehow got the misguided notion that xrange defines 
its own __contains__, so that it would be about the same speed as using 
comparison operators directly. I figured the OP might have a better 
reason for wanting to use range() than his post mentioned -- perhaps the 
range to check was being passed from a function, and it would be easier 
to pass an object than a tuple of lower and upper bound -- but since 
xrange does looping for a membership test, my suggestion was indeed insane.



More information about the Python-list mailing list