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

Leif K-Brooks eurleif at ecritters.biz
Mon Jul 17 22:59:47 EDT 2006


Summercoolness at gmail.com wrote:
> or is there an alternative use of range() or something similar that can
> be as fast?

You could use xrange:

leif at ubuntu:~$ python -m timeit -n10000 "1 in range(10000)"
10000 loops, best of 3: 260 usec per loop
leif at ubuntu:~$ python -m timeit -n10000 "1 in xrange(10000)"
10000 loops, best of 3: 0.664 usec per loop



More information about the Python-list mailing list