python dictionary with constant value-type

Posted by s.kap on Stack Overflow See other posts from Stack Overflow or by s.kap
Published on 2010-05-31T08:47:26Z Indexed on 2010/05/31 8:52 UTC
Read the original article Hit count: 223

hi there,

I bumped into a case where I need a big (=huge) python dictionary, which turned to be quite memory-consuming. However, since all of the values are of a single type (long) - as well as the keys, I figured I can use python (or numpy, doesn't really matter) array for the values ; and wrap the needed interface (in: x ; out: d[x]) with an object which actually uses these arrays for the keys and values storage.

I can use a index-conversion object (input --> index, of 1..n, where n is the different-values counter), and return array[index]. I can elaborate on some techniques of how to implement such an indexing-methods with reasonable memory requirement, it works and even pretty good. However, I wonder if there is such a data-structure-object already exists (in python, or wrapped to python from C/++), in any package (I checked collections, and some Google searches).

Any comment will be welcome, thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about arrays