- I have a dictionary containing
UUID generated for documents like below.
{
"UUID": [
"b8f2904b-dafd-4be3-9615-96bac8e16c7f",
"1240ad39-4815-480f-8cb2-43f802ba8d4e"
]
}
- And another dictionary as a nested one
{
"R_Id": 304,
"ContextKey": "Mr.Dave",
"ConsolidationInformation": {
"Input": [
{
"DocumentCode": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358"
},
{
"DocumentCode": "F16",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_F16.pdf2022-08-010T09:40:06.429358"
}
]
}
}
- I want to add the
UUID by index to the ['ConsolidationInformation']['Input'] and inside individual Input as DocumentUUID, how can I map it using a for a loop. I tried searching on the internet but could not find a solution that could satisfy this nested condition.
- Expected output
{
"R_Id": 304,
"ContextKey": "Mr.Dave",
"ConsolidationInformation": {
"Input": [
{
"DocumentCode": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358",
"DocumentUUID": "b8f2904b-dafd-4be3-9615-96bac8e16c7f"
},
{
"DocumentCode": "F16",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_F16.pdf2022-08-010T09:40:06.429358",
"DocumentUUID": "1240ad39-4815-480f-8cb2-43f802ba8d4e"
}
]
}
}
- I tried something like the below, but it resulted in
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": [
{
"DocumentCode": "BS",
"ObjectType": "Document",
"InputContextKey": "Mr.Dave_HDFC.pdf2022-08-010T09:40:06.429358"
},
{
"DocumentCode": "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}")