나는 두 dicts 있습니다파이썬에서 중첩 된 두 개의 사전을 병합하는 방법은 무엇입니까?
schema = {
'type': 'object',
'properties': {
'reseller_name': {
'type': 'string',
},
'timestamp': {
'type': 'integer',
},
},
'required': ['reseller_name', 'timestamp'],
}
및
schema_add = {
'properties': {
'user_login': {
'type': 'string',
},
},
'required': ['user_login'],
}
을 나는 옆에 얻을 결과 DICT 추가와 통합 할 수 있습니다 방법 :
schema_result = {
'type': 'object',
'properties': {
'reseller_name': {
'type': 'string',
},
'timestamp': {
'type': 'integer',
},
'user_login': {
'type': 'string',
},
},
'required': ['reseller_name', 'timestamp', 'user_login'],
}
규칙 :
같은 경로를 0123의 경우는 properties
이고 required
인 경우 예를 들어,및 scheme_add
.
- 두 명령 모두에 동일한 경로가있는 명령이있는 경우 동일한 규칙으로 병합됩니다.
- 둘 다 dict에 동일한 경로가있는 목록이있는 경우 첫 번째 목록에 초를 추가하십시오.
- dict에 동일한 값 (또는 dict 및 non-dict 또는 list 및 nonlist)이 동일한 경로로 있으면 첫 번째 값이 두 번째 값으로 대체됩니다.
- 하나의 dict만이 키와 값을 설정하는 것보다 경로가있는 키가있는 경우.
질문에 대한 답을 얻은 것 같습니다. 나열된 규칙은 * 귀하의 답변입니다. 이 문제를 구현하는 데 문제가 있습니까? 그렇다면 정확한 문제는 무엇입니까? –
나는 규칙을 나열하기 전에 어려워 보였다. 이제 @ Nicolas78 도움으로 해보겠습니다. – tbicr