set, dict and other structures

Leif K-Brooks eurleif at ecritters.biz
Mon Jan 31 19:45:04 EST 2005


bearophileHUGS at lycos.com wrote:
> I'm frequently using Py2.4 sets, I find them quite useful, and I like
> them, even if they seem a little slower than dicts.

They look exactly the same speed-wise to me:

 >>> t1 = Timer('randrange(100) in foo', 'from random import randrange; 
foo = set(xrange(1000))')
 >>> t2 = Timer('randrange(100) in foo', 'from random import randrange; 
foo = dict.fromkeys(xrange(1000))')
 >>> t1.timeit()
3.0573790073394775
 >>> t2.timeit()
3.064924955368042
 >>> t2.timeit()
3.0590860843658447



More information about the Python-list mailing list