merge python dictionaries
latest version - 0.7.1
Because merging dictionaries in python seems like it should be straightforward, but often it's not.
Merge dictionaries according to the following rules:
The default resolver function will:
Example:
from dictmerge import merge
# define dict1, dict2...
dict1 = {
'foo': 'foo-val',
'bar': { 1: 'one', 2: 'two' },
'baz': 'baz-val'
}
dict2 = {
'foo': 'foo-val',
'bar': { 3: 'three', 4: 'four' },
'quux': 'quux-val'
}
d = merge(dict1, dict2)
assert d == {
'foo': 'foo-val',
'bar': {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
},
'baz': 'baz-val',
'quux': 'quux-val'
}
Example with differing keys:
from dictmerge import merge
# define dict1, dict2...
dict1 = {
'foo': 'foo-val',
}
dict2 = {
'foo': 'other-val',
}
d = merge(dict1, dict2) # throws dictmerge.KeyConflictError
testing is done via py.test, with the tests in test_main.py.
pip install --upgrade git+http://github.com/toejough/dictmerge