Reputation: 9
I have a big dictionary i constantly reference in my code so i have it initialized at the top:
import ...
myDictionary = {'a':'avalue','b':'bvalue',...}
code ...
But when i try to get values, some of the keys are not found. It appears as though Python is chopping my dictionary due to a size limit. I tried searching google but couldn't find anything on this.
I ended up dumping the key:value mappings into a separate file and wrote a function that would build the dictionary by reading in the file.
It would be nice to know why this is happening... even better to find a cleaner way to still have my dictionary.
EDIT: Dictionary has over 1,700 keys
Upvotes: 0
Views: 5192
Reputation: 24662
One thing you might want to look for is that the keys in your dictionary are not duplicates. For example, in the following code:
>>> d = {'1': 'hello', '2': 'world', '1': 'new'}
>>> d
{'1': 'new', '2': 'world'}
>>>
because I used the key '1'
twice, only the last one appeared and thus I was left with a dictionary of size 2 rather than 3.
Upvotes: 4
Reputation: 12004
Python does not have a dictionary size limit. I've had dictionaries with well over 1 million keys. Could you post more of the code?
Upvotes: 2