- 我有一个包含
UUID
个文档的词典,如下所示.
{
"UUID": [
"b8f2904b-dafd-4be3-9615-96bac8e16c7f",
"1240ad39-4815-480f-8cb2-43f802ba8d4e"
]
}
- 和另一本词典作为嵌套词典
{
"R_Id": 304,
"ContextKey": "Mr.Dave",
"ConsolidationInformation": {
"Input": [
{
"Document代码": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358"
},
{
"Document代码": "F16",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_F16.pdf2022-08-010T09:40:06.429358"
}
]
}
}
- 我想将
UUID
by索引添加到['ConsolidationInformation']['Input']
中,并在个体Input
中添加为DocumentUUID
,我如何使用for循环来映射它.我试着在互联网上搜索,但没有找到一个可以满足这个嵌套条件的解决方案. - 预期yields
{
"R_Id": 304,
"ContextKey": "Mr.Dave",
"ConsolidationInformation": {
"Input": [
{
"Document代码": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358",
"DocumentUUID": "b8f2904b-dafd-4be3-9615-96bac8e16c7f"
},
{
"Document代码": "F16",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_F16.pdf2022-08-010T09:40:06.429358",
"DocumentUUID": "1240ad39-4815-480f-8cb2-43f802ba8d4e"
}
]
}
}
- 我try 了下面这样的方法,但结果是
Traceback (most recent call last):
File "<string>", line 26, in <module>
KeyError: 0
- 代码
uuid = {
"UUID": [
"b8f2904b-dafd-4be3-9615-96bac8e16c7f",
"1240ad39-4815-480f-8cb2-43f802ba8d4e"
]
}
document = {
"R_Id": 304,
"ContextKey": "Mr.Dave",
"ConsolidationInformation": {
"Input": [
{
"Document代码": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358"
},
{
"Document代码": "F16",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_F16.pdf2022-08-010T09:40:06.429358"
}
]
}
}
for i, document in enumerate(document):
uuid = uuid[i]
print(f"${uuid} for 1 {document}")