I have this code :
[
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2008",
},
},
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2008",
},
},
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2009",
},
},
]
I want to have :
[
"2008" : [
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2008",
},
},
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2008",
},
},
]
"2009" : [
{
"info": {
"a": 65535,
"b": 50,
},
"test": {
"m": "10300",
"id": "2009",
},
},
]
The idea is to group by key value based on column id. I'm new in python an have no idea how to do that. Please help me. Thx in advance. If you could provide some ideas will be great.I found some examples but can't solve this problem anyway.
My solution :
value = [i for i in array]
res = sorted(value, key=lambda x: x["id"], reverse=True)