【发布时间】:2023-07-27 03:08:01
【问题描述】:
如何将对象/dict(?) 属性传播到新对象/dict 中?
简单的 Javascript:
const obj = {x: '2', y: '1'}
const thing = {...obj, x: '1'}
// thing = {x: '1', y: 1}
Python:
regions = []
for doc in locations_addresses['documents']:
regions.append(
{
**doc, # this will not work
'lat': '1234',
'lng': '1234',
}
)
return json.dumps({'regions': regions, 'offices': []})
【问题讨论】:
-
obj.copy()和new_obj.update({'x': '1'})
标签: javascript python object spread-syntax