We have a large number of Python bytearray strings of variable length which need to remain in memory. Wrt raw-performance, is a Python dictionary the most efficient in-memory storage for read-only random-access for the bytearray strings? The dictionary keys could be integers or strings. If not, what is better?
Share
It all depends on how you intend to access them. If you just want to iterate through them, put them in a
list. If you want to search for one by a key, use adict. No matter what you use, you’ve already paid for the space for all of yourbytearrays, the difference betweenlist,dict, or something else will probably be minimal. A list will use something like 500,000 references at 4 bytes a piece = 2MB, adictmaybe a few times that.