Es gibt zwei Wörterbücher a und b. Sie haben beide eine gemeinsame ID 1. Das Zusammenführen von Diktaten ist dem Ausführungsergebnis in MySQL sehr ähnlich
a = {
"id": "1",
"MUT": "1500",
}
b = {
"id": "1",
"neighbor": [2]
}
# result = addfunction(a,b)
result = {
"id": "1",
"MUT": "1500",
"neighbor": [2]
}
select a.id,a.MUT,b.neighbor from a full join b on a.id = b.id
Bedenken Sie Komplikationen:
a = [
{
"id": "1",
"MUT": "1500",
},
{
"id": "2",
"MUT": "1500",
}
]
b = [
{
"id": "1",
"neighbor": [2]
},
{
"id": "3",
"neighbor": [2]
}
]
# result = addfunction(a,b)
result = [
{
"id": "1",
"MUT": "1500",
"neighbor": [2]
},
{
"id": "2",
"MUT": "1500",
},
{
"id": "3",
"neighbor": [2]
}
]
因为join on 条件可能时多个值,我在stack上找了个代码改了一下。