python已字典为元素的数组排序

dict = [
{'id':'','name':'b'},
{'id':'','name':'c'},
{'id':'','name':'a'},
{'id':'','name':'g'},
{'id':'','name':'f'}
] dict.sort(lambda x,y: cmp(x['id'], y['id']))
dict = sorted(dict, key=lambda x:x['id']) print dict >>[{'id': '', 'name': 'g'}, {'id': '', 'name': 'a'}, {'id': '', 'name': 'b'}, {'id': '', 'name': 'c'}, {'id': '', 'name': 'f'}]
上一篇:Maven中的dependencyManagement 意义


下一篇:Hadoop阅读笔记(六)——洞悉Hadoop序列化机制Writable