Best way to handle large lists?

Hari Sekhon hpsekhon at googlemail.com
Wed Oct 4 04:54:59 EDT 2006


So are you saying that using a dict means a faster search since you only 
need to look up one value?

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?

On the other hand, if it is nearer the end of the set of keys would it 
not be slower?

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?

-h

Hari Sekhon



Fredrik Lundh wrote:
> Hari Sekhon wrote:
>
>   
>> That is surprising since I read on this list recently that lists were 
>> faster than dicts
>>     
>
> depends on what you're doing with them, of course.
>
>   
>> It was one reason that was cited as to why local vars are better than
>>     
>  > 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>
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061004/a6c91649/attachment.html>


More information about the Python-list mailing list