Need to store dictionary in file

Gabriel Genellina gagsl-py2 at
Tue Feb 24 02:47:43 CET 2009

En Mon, 23 Feb 2009 18:38:56 -0200, S.Selvam Siva <s.selvamsiva at>  

> I have a dictionary in which each key is associated with a list as value.
> eg: *dic={'a':['aa','ant','all']}*
> The dictionary contains *1.5 lakh keys*.
> Now i want to store it to a file,and need to be loaded to python program
> during execution.
> I expect your ideas/suggestions.
> Note:I think cPickle,bsddb can be used for this purpose,but i want to  
> know
> the best solution which runs *faster*.

Just try and see. You have to measure performance in your own specific use  
case. What is best for others may not be the best for you; for example,  
your dictionary appears to contain only strings, and this may affect  

I would try:

cPickle with protocol=-1
a cPickle.Pickler object with protocol=-1 , also setting fast=1 in the  
the csv module
a SQL database, like sqlite
a custom format, perhaps one word per line + blank line as separator.

But I would reconsider if having the whole dictionary in memory all the  
time is a good idea. Databases are good for storing and retrieving  

Gabriel Genellina

More information about the Python-list mailing list