Are lists at least as efficient as dictionaries?

John Roth newsgroups at jhrothjr.com
Fri Aug 29 12:16:08 EDT 2003


"Narendra C. Tulpule" <naren at trillium.com> wrote in message
news:781faf41.0308281604.51e48f45 at posting.google.com...
> Hi,
>   if you know the Python internals, here is a newbie question for you.
> If I have a list with 100 elements, each element being a long string,
> is it more efficient to maintain it as a dictionary (with a key = a
> string from the list and value = None) for the purpose of insertion
> and removal?

Lists are more efficient for lookup by index, dictionaries are
more efficient for insertion (except at the end, where Python
maintains extra slots for just this case), removal and lookup
by key. Lists are also much more efficient for sequential
traversal.

John Roth






More information about the Python-list mailing list