Re: Merging two dictionaries

2010-08-02 Thread Paul Rubin
Douglas Garstang writes: > where line 42 is 'assert type(default(k))==dict', and the inputs are: Woops, cut and paste error. default(k) should say default[k]. Or you could remove the assertion altogether. -- http://mail.python.org/mailman/listinfo/python-list

Re: Merging two dictionaries

2010-08-02 Thread Douglas Garstang
On Mon, Aug 2, 2010 at 1:09 AM, Peter Otten <__pete...@web.de> wrote: > Douglas Garstang wrote: > >> I have the two dictionaries below. How can I merge them, such that: >> >> 1. The cluster dictionary contains the additional elements from the >> default dictionary. >> 2. Nothing is removed from the

Re: Merging two dictionaries

2010-08-02 Thread Peter Otten
Douglas Garstang wrote: > On Mon, Aug 2, 2010 at 12:47 AM, Paul Rubin wrote: >> If yes, then the following works for me: >> >>def merge(cluster, default): >># destructively merge default into cluster >>for k,v in cluster.iteritems(): >>if k in default and type(v)

Re: Merging two dictionaries

2010-08-02 Thread Douglas Garstang
On Mon, Aug 2, 2010 at 12:47 AM, Paul Rubin wrote: > Douglas Garstang writes: >> default = {... >>                 'data_sources': { ... >> cluster = {... >>                 'data_source': { ... > > Did you want both of those to say the same thing instead of one > of them being 'data_source' and

Re: Merging two dictionaries

2010-08-02 Thread Peter Otten
Douglas Garstang wrote: > I have the two dictionaries below. How can I merge them, such that: > > 1. The cluster dictionary contains the additional elements from the > default dictionary. > 2. Nothing is removed from the cluster dictionary. def inplace_merge(default, cluster): assert isinsta

Re: Merging two dictionaries

2010-08-02 Thread Paul Rubin
Douglas Garstang writes: > default = {... > 'data_sources': { ... > cluster = {... > 'data_source': { ... Did you want both of those to say the same thing instead of one of them being 'data_source' and the other 'data_sources' ? If yes, then the following works fo

Re: Merging two dictionaries

2010-08-02 Thread Chris Rebert
On Mon, Aug 2, 2010 at 12:06 AM, Douglas Garstang wrote: > Actually, I had issues with trying recurse through the structures in > tandem too. This didn't work: > > for a,b,c,d in ( cluster.iteritems(), default.iteritems() ): >    ... do something ... > > It returns an unpack error. Well, yeah. Th

Re: Merging two dictionaries

2010-08-02 Thread Douglas Garstang
On Sun, Aug 1, 2010 at 11:57 PM, Gary Herron wrote: > On 08/01/2010 11:11 PM, Douglas Garstang wrote: >> >> On Sun, Aug 1, 2010 at 10:58 PM, Gary Herron >>  wrote: >> >>> >>> On 08/01/2010 10:09 PM, Douglas Garstang wrote: >>> Anyone, I have the two dictionaries below. How can

Re: Merging two dictionaries

2010-08-02 Thread Gary Herron
On 08/01/2010 11:11 PM, Douglas Garstang wrote: On Sun, Aug 1, 2010 at 10:58 PM, Gary Herron wrote: On 08/01/2010 10:09 PM, Douglas Garstang wrote: Anyone, I have the two dictionaries below. How can I merge them, such that: 1. The cluster dictionary contains the additional elements

Merging two dictionaries

2010-08-01 Thread Douglas Garstang
Anyone, I have the two dictionaries below. How can I merge them, such that: 1. The cluster dictionary contains the additional elements from the default dictionary. 2. Nothing is removed from the cluster dictionary. The idea here is that the two dictionaries are read from different files where, i