我有一个 json,它是一个字典列表,如下所示:
我使用 pymysql 从 MySQL 获取它
[{
"id": "123",
"name": "test",
"group": "test_group"
},
{
"id": "123",
"name": "test",
"group": "test2_group"
},
{
"id": "456",
"name": "test2",
"group": "test_group2"
},
{
"id": "456",
"name": "test2",
"group": "test_group3"
}]
Run Code Online (Sandbox Code Playgroud)
我需要对其进行分组,以便每个“名称”只有一个字典,并且它将包含该名称下所有组的列表。像这样的东西:
[{
"id": "123",
"name": "test",
"group": ["test2_group", "test_group"]
},
{
"id": "456",
"name": "test2",
"group": ["test_group2", "test_group3"]
}]
Run Code Online (Sandbox Code Playgroud)
我想得到一些帮助,谢谢!