按特定顺序排列字典列表 [英] Sorting list of dictionaries according to specific order
本文介绍了按特定顺序排列字典列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
最好的(和一般的)解决方案似乎在这里给出:在python中任意排列的列表
I am using Python 2.6 and I have two data stores. Querying the first one returns a list of document IDs in a specific order. I look up all the documents at once in the second data store using these IDs, which returns a list of dictionaries (one for each doc), but not in the same order as the original list. I now need to re-sort this list of dictionaries so that the documents are in the order that their IDs were in the first list. What's the best way of doing this?
解决方案
The best (and general) solution seems to be given here: reordering list of dicts arbitrarily in python
这篇关于按特定顺序排列字典列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文