【发布时间】:2015-04-14 00:06:22
【问题描述】:
我的 JSON 列表如下所示:
[{ "id": "1", "score": "100" },
{ "id": "3", "score": "89" },
{ "id": "1", "score": "99" },
{ "id": "2", "score": "100" },
{ "id": "2", "score": "59" },
{ "id": "3", "score": "22" }]
我想先对id排序,我用过
sorted_list = sorted(json_list, key=lambda k: int(k['id']), reverse = False)
这只会按id对列表进行排序,但是根据id,我也想对分数进行排序,我想要的最终列表是这样的:
[{ "id": "1", "score": "100" },
{ "id": "1", "score": "99" },
{ "id": "2", "score": "100" },
{ "id": "2", "score": "59" },
{ "id": "3", "score": "89" },
{ "id": "3", "score": "22" }]
因此,对于每个 id,也要对其分数进行排序。知道该怎么做吗?
【问题讨论】: