Access dictionary in order?
Diego Dainese
ddainese55x at x89dsi.unive.it
Tue Jul 27 17:00:01 EDT 1999
On Mon, 26 Jul 1999 07:45:29 -0700, Emile van Sebille wrote:
[...]
> > But how much time requires the keylist generation?
>
> I tried this test and found that the results varied on the number of
> items. For example,
[snip]
You are right, my question was a bit naive...
> > That is, the keylist is made traversing all the dictionary nodes or is
> > cached inside it?
>
> I can't help you with this one...
AFAICT (from you test program) the nodes are linked in a list and the
key-sequence is generated traversing this list. Moreover the sequence
is not cached:
import time
d = {}
r = ('spam','eggs','eggs','bacon','eggs','and','spam')
k = []
for i in xrange(1000000):
d[i] = i, 2*i, r
k.append(i)
test1start = time.clock()
k = d.keys()
test1end = test2start = time.clock()
k = d.keys()
test2end = time.clock()
print 'test1: ',test1end - test1start
print 'test2: ',test2end - test2start
The last 2 prints give always the same results (about 0.8 seconds on
my Linux box).
> > --
> > Sorry for my bad English!
>
> Not bad at all.
Thanks :)
+++
Thanks for the reply (and to Skip Montanaro too), bye
--
Diego Dainese
--
To reply remove the numbers and the `x' from my address
--
Sorry for my bad English!
More information about the Python-list
mailing list