Deep merge two dicts?

John Nagle nagle at animats.com
Thu Apr 12 13:59:02 EDT 2012


On 4/12/2012 10:41 AM, Roy Smith wrote:
> Is there a simple way to deep merge two dicts?  I'm looking for Perl's
> Hash::Merge (http://search.cpan.org/~dmuey/Hash-Merge-0.12/Merge.pm)
> in Python.

def dmerge(a, b) :
    for k in a :
         v = a[k]
         if isinstance(v, dict) and k in b:
             dmerge(v, b[k])
    a.update(b)
	
	




More information about the Python-list mailing list