Better dict of dicts

John Bauman john at baumanfamily.com
Thu Apr 19 17:40:27 EDT 2007


Adam Atlas wrote:
> On Apr 19, 5:24 pm, Bill Jackson <jack... at hotmail.com> wrote:
>> I have a dictionary of dictionaries where the keys are typically very
>> long tuples and repeated in each inner dictionary.  The dictionary
>> representation is nice because it handles sparseness well...and it is
>> nice to be able to look up values based on a string rather than a
>> number.  However, since my keys are quite long, I worry that I am
>> wasting a lot of memory.
> 
> I wouldn't worry about it. Try doing hash('string_2') in the
> interpreter -- the output thereof is what's really being used as the
> key. It doesn't use up any more memory than the integer 2.
> 
Are you sure about that? Most dictionaries need to store the actual key, 
in case of a collision, so when you lookup a key they can tell which 
you're really looking for.



More information about the Python-list mailing list