efficient updating of nested dictionaries

Sidharthk sidharthk at hotmail.com
Mon Jan 26 10:01:16 CET 2004


omission9 <omission9 at invalid.email.info> wrote in message news:<H%_Qb.2609$925.1917 at nwrddc02.gnilink.net>...
> I have a dictionary that looks like this
> MY_DICT[KEY_X][KEY_Y][KEY_Z]=FOO
> 
> I am having a problem updating this with a simple 
> MY_DICT.update(NEW_DICT) as update doesn't seem to care about getting 
> into the inner dicts.
> Getting the keys of each and iterating through and updating each one is 
> terribly slow as the number of keys gets bigger and bigger.
> What is the bst way to update my nested dicts?

Use Tuples

MY_DICT[(KEY_X,KEY_Y,KEY_Z)]=FOO

Unless for some you need to use nested dicts :)



More information about the Python-list mailing list