【发布时间】:2013-04-08 13:53:08
【问题描述】:
假设我有这些列表:
ids = [4, 3, 7, 8]
objects = [
{"id": 7, "text": "are"},
{"id": 3, "text": "how"},
{"id": 8, "text": "you"},
{"id": 4, "text": "hello"}
]
我怎样才能对objects 进行排序,使其ID 的顺序与ids 匹配? IE。得到这个结果:
objects = [
{"id": 4, "text": "hello"},
{"id": 3, "text": "how"},
{"id": 7, "text": "are"},
{"id": 8, "text": "you"}
]
【问题讨论】: