Not sure what the exact intent of resizing the dict is...however, if you wish to reduce the overall memory consumption of your python process...i would suggest:
- copy the required contents to a new dict..(use dict comprehension if you can) >>> d2 = dict((k,v) for k,v in d1.items() if <insert your conditions here>) - Assign the old dict name to None >>> d1 = None - do a gc.collect() >>> import gc >>> gc.collect() you should see immediate results on process memory consumption. Enjoy Python Vishal Sapre On Wed, Apr 17, 2013 at 9:22 PM, Rahul R <rahul8...@gmail.com> wrote: > Ahh , sorry If i wasnt clear the first time. I dint mean reorder the data > in dictionary. I meant resize the dictionary. > > ./Rahul > > On Wed, Apr 17, 2013 at 9:05 PM, Anand Chitipothu <anandol...@gmail.com > >wrote: > > > dictionaries are unordered. It is not a good idea to expect any order in > > dictionaries, even if you are seeing some order by chance. > > > > If you need order, then use OrderedDict from collections module (new in > > Python 2.7). > > > > Anand > > > > > > On Wed, Apr 17, 2013 at 9:00 PM, Rahul R <rahul8...@gmail.com> wrote: > > > > > Hey Guys, > > > > > > Is it possible to forcibly reorder the python dictionary after "n" > number > > > of inserts and deletions. As far as i know, python dictionary performs > > lazy > > > deletes. Thus , even if the data is deleted, python has a dummy data > > their > > > in order to preserve consistency. The python dictionary > > > keeps expanding when the size of dict is increasing, but after > deleting a > > > few parameters the size does not decrease. Is there a way , where I can > > > forcibly resize the dictionary ? > > > > > > I was thinking of copying content from existing dictionary to new dict > > and > > > deleting the previous one.But thats a cumbersome operation. > > > > > > Thanks, > > > ./Rahul > > > _______________________________________________ > > > BangPypers mailing list > > > BangPypers@python.org > > > http://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > > > -- > > Anand > > http://anandology.com/ > > _______________________________________________ > > BangPypers mailing list > > BangPypers@python.org > > http://mail.python.org/mailman/listinfo/bangpypers > > > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- Thanks and best regards, Vishal Sapre --- "Life is 10% how you make it, and 90% how you take it" "बहुजन हिताय, बहुजन सुखाय (Benefit for most people, Happiness for most people.)" --- Please DONT print this email, unless you really need to. Save Energy & Paper. Save the Earth. _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers