说明性示例:
d1 = {
"ean_code": ["OA13233394CN08", "8903327046534", "8903327014779"],
"balance_qty": [5, 10, 15]
}
和
d2 = {
"ean_code": ["OA13233394CN11", "OA13233394CN08", "8903327014779", "OA13233394CN09"],
"scanned_qty": [30, 5, 20, 10, - 1],
}
输出:
d3 = {
"ean_code": ["OA13233394CN08", "8903327046534", "8903327014779", "OA13233394CN11", "OA13233394CN09"],
"scanned_qty": [5, 0, 20, 30, 10],
"balance_qty": [5, 10, 15, 0, 0]
}
解释。d3['scanned_qty'][1]
默认值为0
,因为 is 的值d3['ean_code'][1]
属于d1['ean_code']
数组且d1
对象没有scanned_qty
键。
执行此操作的最佳方法?