On 2006-07-18, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > it seems that range() can be really slow: > > the following program will run, and the last line shows how long it ran > for: > > import time > > startTime = time.time() > > a = 1.0 > for i in range(0, 30000): > if i in range (0, 10000): > a += 1 > if not i % 1000: print i > > print a, " ", round(time.time() - startTime, 1), "seconds"
> or is there an alternative use of range() or something similar that can > be as fast? Creating and then searching a 10,000 element list to see if a number is between two other numbers is insane. Using xrange as somebody else suggested is also insane. If you want to know if a number is between two other numders, for pete's sake use the comparison operator like god intended. if 0 <= i <= 10000: -- Grant Edwards grante Yow! ANN JILLIAN'S HAIR at makes LONI ANDERSON'S visi.com HAIR look like RICARDO MONTALBAN'S HAIR! -- http://mail.python.org/mailman/listinfo/python-list