举例:
import operator
x = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] sorted_x = sorted(x, key=operator.itemgetter('name'))
print sorted_x
----------------------------- [{'age': 10, 'name': 'Bart'}, {'age': 39, 'name': 'Homer'}]
倒序输出:只需要加1个参数reverse=True即可:
sorted_x = sorted(x, key=operator.itemgetter('name'),reverse=True)