Leif K-Brooks wrote: > [EMAIL PROTECTED] wrote: > > or is there an alternative use of range() or something similar that can > > be as fast? > > You could use xrange: > > [EMAIL PROTECTED]:~$ python -m timeit -n10000 "1 in range(10000)" > 10000 loops, best of 3: 260 usec per loop > [EMAIL PROTECTED]:~$ python -m timeit -n10000 "1 in xrange(10000)" > 10000 loops, best of 3: 0.664 usec per loop
That's only because you're choosing a number that's early in the list. ~$ python -m timeit -n10000 "1 in xrange(10000)" 10000 loops, best of 3: 1.22 usec per loop ~$ python -m timeit -n10000 "9999 in xrange(10000)" 10000 loops, best of 3: 1.24 msec per loop That's *milliseconds*, not microseconds. -- http://mail.python.org/mailman/listinfo/python-list