【发布时间】:2020-07-14 14:53:22
【问题描述】:
我在下面有一本字典:
event = {
"body-json": {},
"params": {
"path": {
"matchphrase": "term"
},
"querystring": {
"dataproduct.keyword": "health"
},
"header": {
"Accept": "application/json"
}
},
"resource-path": "/{matchphrase}"
}
我想访问上面的event 字典键和值并按如下方式构建一个新字典:
{"query": {"term" : {"dataproduct.keyword": "health"}}}
这是我尝试过的代码:
a = event['params']['path']['matchphrase'] #term
b = list(event['params']['querystring'].keys())[0] #dataproduct.keyword
c = list(event['params']['querystring'].values())[0] #health
body=f"{query: {{a} : {{b}: {c}}}}"
print(body)
我错过了什么吗?
【问题讨论】:
-
body = f'{{"query": {{{a}: {{{b}: {c}}}}}}}'
标签: python dictionary