Best way to handle large lists?
Jeremy Sanders
jeremy+complangpython at jeremysanders.net
Tue Oct 3 12:44:53 EDT 2006
Jeremy Sanders wrote:
> Chaz Ginger wrote:
>
>> What would sets do for me over lists?
>
> It's faster to tell whether something is in a set or dict than in a list
> (for some minimum size).
As a footnote, this program
import random
num = 100000
a = set( range(num) )
for i in range(100000):
x = random.randint(0, num-1) in a
completes in less than a second, whereas
import random
num = 100000
a = range(num)
for i in range(100000):
x = random.randint(0, num-1) in a
takes a long time on my computer.
Jeremy
--
Jeremy Sanders
http://www.jeremysanders.net/
More information about the Python-list
mailing list