I believe that, as stated above, using d2.update(d1)
is the best approach and that you can also copy d2
first if you still need it.
Although, I want to point out that dict(d1, **d2)
is actually a bad way to merge dictionnaries in general since keyword arguments need to be strings, thus it will fail if you have a dict
such as:
{
1: 'foo',
2: 'bar'
}