<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
So are you saying that using a dict means a faster search since you
only need to look up one value?<br>
<br>
I would think that you would have to look through the keys and stop at
the first key that matches since each key has to be uniq, so perhaps if
it is nearer the front of the set of keys then perhaps it would be a
quicker lookup?<br>
<br>
On the other hand, if it is nearer the end of the set of keys would it
not be slower?<br>
<br>
Does this make it more dependent on the search order whether a list or
a dict is faster? Or am I completely on the wrong track?<br>
<br>
-h<br>
<pre class="moz-signature" cols="72">Hari Sekhon</pre>
<br>
<br>
Fredrik Lundh wrote:
<blockquote cite="midefuced$10f$1@sea.gmane.org" type="cite">
<pre wrap="">Hari Sekhon wrote:
</pre>
<blockquote type="cite">
<pre wrap="">That is surprising since I read on this list recently that lists were
faster than dicts
</pre>
</blockquote>
<pre wrap=""><!---->
depends on what you're doing with them, of course.
</pre>
<blockquote type="cite">
<pre wrap="">It was one reason that was cited as to why local vars are better than
</pre>
</blockquote>
<pre wrap=""><!----> > global vars.
L[int] is indeed a bit faster than D[string] (but not much), but that
doesn't mean that you can loop over *all* items in a list faster than
you can look up a single key in a dictionary.
</F>
</pre>
</blockquote>
</body>
</html>