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/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to