DicMer
DicMer -- это небольшой, простой и удобный в использовании Python-пакет, предназначенный для рекурсивного объединения словарей.
Например, следующий код:
from dicmer import dict_merge
a = {
'string': 'Lorem Ipsum',
'dicts': {
'b1': 'It is simply dummy text',
'b2': {
'b2_1': 'Printing and typesetting industry',
'b2_2': 'It has survived not only five centuries',
}
},
'list': [
'What is Lorem Ipsum?',
'Where does it come from?',
]
}
b = {
'dicts': {
'b2': {
'b2_1': 'WARNING: This key was overwritten!',
'b2_3': 'WARNING: This key was aded!',
},
'b3': 'WARNING: This key was added!'
},
'list': [
'Why do we use it?',
'Where can I get some?',
],
'new key': {
'I am': 'a new string!'
}
}
print(dict_merge(a, b))
Выдаст следующий результат:
{
'string': 'Lorem Ipsum',
'dicts': {
'b1': 'It is simply dummy text',
'b2': {
'b2_1': 'WARNING: This key was overwritten!',
'b2_2': 'It has survived not only five centuries',
'b2_3': 'WARNING: This key was aded!'
},
'b3': 'WARNING: This key was added!'
},
'list': [
'What is Lorem Ipsum?',
'Where does it come from?',
'Why do we use it?',
'Where can I get some?'
],
'new key': {
'I am': 'a new dict!'
}
}