I am having two complex data structure(i.e. _to and _from), I want to override the entity of _to with the same entity of _from. I have given this example.
# I am having two data structure _to and _from
# I want to override _to from _from
_to = {'host': 'test',
'domain': [
{
'ssl': 0,
'ssl_key': '',
}
],
'x': {}
}
_from = {'status': 'on',
'domain': [
{
'ssl': 1,
'ssl_key': 'Xpyn4zqJEj61ChxOlz4PehMOuPMaxNnH5WUY',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq'
}
]
}
### I want this output
_result = {'host': 'test',
'status': 'on',
'domain': [
{
'ssl': 1,
'ssl_key': 'Xpyn4zqJEj61ChxOlz4PehMOuPMaxNnH5WUY',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq'
}
],
'x': {}
}
Use case 2:
_to = {'host': 'test',
'domain': [
{
'ssl': 0,
'ssl_key': '',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq',
"abc": [],
'https': 'no'
}
],
'x': {}
}
_from = {
'domain': [
{
'ssl': 1,
'ssl_key': 'Xpyn4zqJEj61ChxOlz4PehMOuPMaxNnH5WUY',
'ssl_cert': 'nuyickK8uk4VxHissViL3O9dV7uGSLF62z52L4dAm78LeVdq'
}
]
}
dict.update(dict2) won't help me, because this will delete the extra keys in _to dict.
It's quite simple:
_to.update(_from)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With