I need to create an in memory object that has keys that are a 9 digit integer and a boolean value associated with each key. I've been using a dict as in the simplified example below:
#!/usr/bin/python
from __future__ import print_function
import sys
myDict = {}
for n in range(56000):
myDict[n] = True
print('Count:',len(myDict),' Size:', sys.getsizeof(myDict))
I need to be able to look up and retrieve the boolean value associated with each key. The problem is the size of the dict. Using Python 2.7 on a 64 bit Linux system and the above example, the size of the dict is 3.1 megabytes according to sys.getsizeof(). (about 56 bytes per entry to store 9 digits plus a boolean value)
I need to store the boolean state of (approx) 55.000 entries in the dict. Each dict key is a 9 digit integer. I've tried using the integer and str(theInteger) as keys with no change in the size of the dict.
Is there some other sort of data structure or methodology I should be using to conserve memory with such a large data set?