I have a list of ordered dict that includes some duplicate identifiers in the data .. something like this
[OrderedDict([('caseId', 20), ('userId', 1), ('emailStatus', 21)]),
OrderedDict([('caseId', 20), ('userId', 1), ('emailStatus', 20)]),
OrderedDict([('caseId', 18), ('userId', 4), ('emailStatus', 21)]),
OrderedDict([('caseId', 19), ('userId', 3), ('emailStatus', 21)]),
OrderedDict([('caseId', 18), ('userId', 1), ('emailStatus', 20)]),
OrderedDict([('caseId', 20), ('userId', 3), ('emailStatus', 21)]),
OrderedDict([('caseId', 18), ('userId', 4), ('emailStatus', 20)]),
OrderedDict([('caseId', 19), ('userId', 1), ('emailStatus', 20)])]
I want to get a list of nested lists, something like this:
[{
"caseId": "20",
"users": [
{
"userId": "1",
"emailStatus": [
{
"emailStatus" : "20"
},
{
"emailStatus" : "21"
}
]
},
{
"userId": "3",
"emailStatus": [
{
"emailStatus" : "21"
}
]
}
]
},
{
"caseId": "19",
"users": [
{
"userId": "1",
"emailStatus": [
{
"emailStatus" : "20"
}
]
},
{
"userId": "3",
"emailStatus": [
{
"emailStatus" : "21"
}
]
}
]
},
{
"caseId": "18",
"users": [
{
"userId": "1",
"emailStatus": [
{
"emailStatus" : "20"
}
]
},
{
"userId": "4",
"emailStatus": [
{
"emailStatus" : "20"
},
{
"emailStatus" : "21"
}
]
}
]
}
]
Represents a nested list like this;

I tried to achieve this, iterate over both lists, but could not figure out how to record previous and next records of the same data. This is so confusing. If anyone can give me a start that I can repeat my list, that would be very kind of you.
Yours faithfully..
Updated Question
More detailed question here