原文发于:http://qing.weibo.com/2059598087/7ac2f907330025yy.html
如何利用外部列表元素顺序对源列表进行排序
unordered = ["242 C", "022 B", "019 A", "025 D"] ordered = ["A", "B", "G"] ##根据待排序列表中的项提取出key。以字典形式存储 d = {} for line in unordered: name = line.split()[1] d[name] = line ##利用排序规则从字典中读取数据 result = [] for key in ordered: item = d.get(key, None) if item != None: del d[key] result.append(item) ##得到最后结果 result += [d[item] for item in d] ##排序结果 ##['019 A', '022 B', '242 C', 025 D''] ##或['019 A', '022 B', 025 D'', '242 C']