I was working on a project that involves loading a relatively large dictionary into memory from a file. The dictionary has less than 2 million entries, each entry (key and value combined) is less than 20 bytes. The file size on the disk is 38 MB.
My problem is that when I try to load a dictionary, my program immediately expands to 2.5 gigabytes of used memory.
Here is the code I use to read the dictionary from disk:
f = open('someFile.txt', 'r')
rT = eval(f.read())
f.close()
source
share