item access time: sets v. lists

2006-10-04 Thread David Isaac
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(1)):pass","") >>> t2=timeit.Timer("for i in list(xrange(1)):pass","") >>> t1.timeit(1000) 9.806250235714316 >>> t2.timeit(1000

Re: item access time: sets v. lists

2006-10-04 Thread Dennis Benzinger
On Wed, 04 Oct 2006 16:02:56 GMT "David Isaac" <[EMAIL PROTECTED]> 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(1)):pass","") > >>> t2=timeit.Timer("for i

Re: item access time: sets v. lists

2006-10-04 Thread Paul McGuire
"David Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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(1)):pass","") t2=timeit.Timer("for i in

Re: item access time: sets v. lists

2006-10-04 Thread David Isaac
Paul M. wrote: > Random access to item in list/set when item exists > set -> 0.000241650824337 > list -> 0.0245168031132 > > Random access to item in list/set when item does not exist > set -> 0.000187733357172 > list -> 0.522086186932 OK, that's a much better set of answers including to questi

Re: item access time: sets v. lists

2006-10-04 Thread Neil Cerutti
On 2006-10-04, David Isaac <[EMAIL PROTECTED]> wrote: > Paul M. wrote: >> Random access to item in list/set when item exists >> set -> 0.000241650824337 >> list -> 0.0245168031132 >> >> Random access to item in list/set when item does not exist >> set -> 0.000187733357172 >> list -> 0.52208618693

Re: item access time: sets v. lists

2006-10-04 Thread Paul McGuire
"Neil Cerutti" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Look at the code again. It's not testing what it says it's > testing. > It isnt? The only quibble I can see is that there really is no "first" element in a set. I picked the "0 in set" and "0 in list" to pick the fa

Re: item access time: sets v. lists

2006-10-04 Thread Paul McGuire
"David Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Paul M. wrote: >> Random access to item in list/set when item exists >> set -> 0.000241650824337 >> list -> 0.0245168031132 >> >> Random access to item in list/set when item does not exist >> set -> 0.000187733357172 >>

Re: item access time: sets v. lists

2006-10-04 Thread Duncan Booth
"Paul McGuire" <[EMAIL PROTECTED]> wrote: > By contrast, a set (and also the keys in a dict) use a tree structure > to index more quickly into the list of items 'dict' and I believe also 'set' use a hash table, not a tree structure. -- http://mail.python.org/mailman/listinfo/python-list

Re: item access time: sets v. lists

2006-10-04 Thread Neil Cerutti
On 2006-10-04, Paul McGuire <[EMAIL PROTECTED]> wrote: > "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> Look at the code again. It's not testing what it says it's >> testing. > > It isnt? > > The only quibble I can see is that there really is no "first" > element

Re: item access time: sets v. lists

2006-10-04 Thread [EMAIL PROTECTED]
David Isaac wrote: > Paul M. wrote: > > Random access to item in list/set when item exists > > set -> 0.000241650824337 > > list -> 0.0245168031132 > > > > Random access to item in list/set when item does not exist > > set -> 0.000187733357172 > > list -> 0.522086186932 > > > OK, that's a much be

Re: item access time: sets v. lists

2006-10-04 Thread Paul McGuire
"Neil Cerutti" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 2006-10-04, Paul McGuire <[EMAIL PROTECTED]> wrote: >> "Neil Cerutti" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > > It seems to be timing "testing for membership", not "random > access". Random

Re: item access time: sets v. lists

2006-10-04 Thread Paul McGuire
"Duncan Booth" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Paul McGuire" <[EMAIL PROTECTED]> wrote: > >> By contrast, a set (and also the keys in a dict) use a tree structure >> to index more quickly into the list of items > > 'dict' and I believe also 'set' use a hash table, no

Re: item access time: sets v. lists

2006-10-04 Thread Duncan Booth
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > A set, on the other hand, uses a hash table so finding an element > takes constant time (it's one hash lookup, independent of the size of > the set)--and determining an item isn't there is likewise constant > time. > One hash calculation, but ther