efficient updating of nested dictionaries
rmkrauter at yahoo.com
Mon Jan 26 04:37:19 CET 2004
The following is probably too dependent on the data type of the keys,
but it may be suitable in some programs. It's certainly not a general
solution for all cases. Others will have much better ideas, but here
goes anyway ...
You may want to use a non-nested dict with a 'superkey' composed of the
concatenation of the three keys, seperated by some delimiter.
Then you could use update().You would just have to do some pre- and
post-processing of the keys. i.e. splitting or joining the 'superkey' by
the delimiter you choose.
Although, that's probably kind of lame - I bet others will have much
better suggestions. I'm interested in how other people do this too.
On Sun, 2004-01-25 at 21:33, omission9 wrote:
> I have a dictionary that looks like this
> 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list