Lists, tuples and memory.

Elbert Lev elbertlev at hotmail.com
Fri Jul 16 16:26:07 CEST 2004


"Larry Bates" <lbates at swamisoft.com> wrote in message news:<CLednf1kspFPeGvd4p2dnA at comcast.com>...
> Any reason not to put the words into a dictionary?
> 
> Then your code becomes:
> 
> lstdict=dict([(x.lower().strip(), None) for x in
>               file("D:\\CommonDictionary.txt")])
> 
> 
> if lstdict.has_key(word):
>   do something
> 
> (not tested, but should be close)
> 
> I'll bet access is faster (even if loading is slightly slower).
> You also benefit from the fact that the dictionary file
> doesn't need to be kept sorted.
> 
> HTH,
> Larry Bates
> Syscon, Inc.
> 

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.

Off topic: isn't this a great feature of Python? In almost no time I
checked several data representations and was abble to choose the best
for my case. In C++, even with stl, such research would take at least
a day.



More information about the Python-list mailing list