Lists, tuples and memory.
Christopher T King
squirrel at WPI.EDU
Fri Jul 16 11:30:51 EDT 2004
On 16 Jul 2004, Elbert Lev wrote:
> "Larry Bates" <lbates at swamisoft.com> wrote in message news:<CLednf1kspFPeGvd4p2dnA at comcast.com>...
> > Any reason not to put the words into a dictionary?
>
> Dictionary has the almost 100 times faster access time theb bisect of
> a list. Build time is about 1 second (very good). Memory consumption
> almost 8 MB - 2.5 times higher then with the list (not too good).
> Unless very fast access time is an imperative, I'd rather not to use
> it.
Try using a set instead of a dictionary. You should get the good access
time of dictionaries with nearly the low memory usage of a list:
from sets import Set
lstdict=Set([x.lower().strip() for x in file("D:\\CommonDictionary.txt")])
if word in lstdict:
<do something>
Combine the above with the suggestions to use generators for best
performance.
Also available is sets.ImmutableSet. I'm not sure if this provides
enhanced performance over Set though.
More information about the Python-list
mailing list