item access time: sets v. lists

Dennis Benzinger Dennis.Benzinger at
Wed Oct 4 18:22:38 CEST 2006

On Wed, 04 Oct 2006 16:02:56 GMT
"David Isaac" <aisaac0 at> wrote:

> Is it expected for access to set elements to be much
> slower than access to list elements?  Explanation?
> Thanks,
> Alan Isaac
> >>> t1=timeit.Timer("for i in set(xrange(10000)):pass","")
> >>> t2=timeit.Timer("for i in list(xrange(10000)):pass","")
> [...]

You're measuring the time for creating the xrange and the set/list too.
Create them before you call Timer() and repeat your timing.

Dennis Benzinger

More information about the Python-list mailing list