假設我有這些列表:排序一個列表,以匹配另一個在python
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
?即要得到這樣的結果:
objects = [
{"id": 4, "text": "hello"},
{"id": 3, "text": "how"},
{"id": 7, "text": "are"},
{"id": 8, "text": "you"}
]
我想我會的因素字典-COMP,所以你不是在一遍又一遍的做。 – mgilson 2013-04-08 13:56:07