0

I am using a dictionary whose number of keys start from 0 and reach to a point where the number of keys are 1e5. How can I initialize the slot size of dictionary to avoid resizing cost (By default the slot size initially is 8)?

Note: I don't know the keys initially. Only thing that I know is that finally the number of keys will be 1e5.

Luv Agarwal
  • 183
  • 2
  • 7
  • 3
    There's no way to do that; if you need such precise control over the underlying objects, Python may not be the language for you. – jonrsharpe Feb 14 '16 at 13:21
  • 4
    http://stackoverflow.com/questions/3020514/is-it-possible-to-give-a-python-dict-an-initial-capacity-and-is-it-useful OR http://stackoverflow.com/questions/1298636/how-to-set-initial-size-for-a-dictionary-in-python – riteshtch Feb 14 '16 at 13:21
  • I can't imagine that resizing cost is really an issue, especially since the Python implementation will so something which is already fairly optimized. If you have 1e5 elements you are likely doing a fair amount of computation where resizing would be just a small drop in the bucket. – John Coleman Feb 14 '16 at 13:57

0 Answers0