#coding:utf-8
def test():
m = [{'x':20, 'value':'aaaaa'},{'x':15, 'value':'bbbbb'},{'x':22, 'value':'abcdefg'},{'x':30, 'value':'gggggg'}]
print m
result = sorted(m, key = sort_test) #顺序
#result = sorted(m, key = sort_test, reverse = True) #倒序
return result
def sort_test(c):
return c["x"] #按字典的''x''字段进行排序
print test()
网友评论